I ran into some troubles migrating/configuring my tables for a new app in my Django project.
I’ve been following this excellent tutorial, and ran into a bump I thought needed some clarification/update. As I’m not sure if the guide is up to date with the current version of Django.
Things I searched:
no module named models
django not creating db
models are not being created in sqlite3 Django
sqlite3 not creating table django
No migrations to apply
django sqlite3 unable to create tables
sqlite3 python package
Do these correlate with what you’re having issues with?
If so this was my solution.
First Install SQLite3 and add it too your Environment Variables -> Path
Install Page — Select: Source Code -> Zip for windows machines
I extracted it to C:/.
Now I have SQLite.exe in my root directory.
This is what the end of my Path looks like:
C:\Program Files\Microsoft\Web Platform Installer\;C:\SQLITE3.EXE\;
Sweet, now we can use SQLite in Powershell.
Configuration of Visual Studio:
Create a new app by right clicking on your Project file.
Then “Add” -> Select “Django App”
In this case my app is named book.
Sweet, now we have another Python app.
Go into your settings file and add it to the INSTALLED_APPS tuple.
Okay, now we’re configured make sure you’re SQLiteDB is properly configured as well.
‘NAME’: path.join(PROJECT_ROOT, ‘db.sqlite3’),
Sweet, db all locked and loaded.
Next we’ll create a model.
Following along with the tutorial.
We go into: book -> models.py and create our models.
name = models.CharField(max_length=30)
address = models.CharField(max_length=50)
city = models.CharField(max_length=60)
state_province = models.CharField(max_length=30)
country = models.CharField(max_length=50)
website = models.URLField()
Sweet. Model made. Let’s get it into our SQLite DB.
Alright now in DjangoProject1Hack (Where ‘ls’ will show db.sqlite3 among others)
We’ll be doing the migration.
Run- C:\Python27\python.exe manage.py validate
Run- C:\Python27\python.exe manage.py makemigrations
Migrations for ‘book’:
– Create model Author
– Create model Book
– Create model Publisher
– Add field publisher to book
3. Sync (This just makes sure we add what’s missing)
Run- C:\Python27\python.exe manage.py syncdb
Operations to perform:
Apply all migrations: book
Applying book.0001_initial… OK
Okay now we manage the db:
Run- C:\Python27\python.exe manage.py shell
Sample workflow in Shell:
>>> from book.models import Publisher
>>> p1 = Publisher(name=’Apress’, address=’2855 Telegraph ave’, city=’berkely’, state_province=’CA’, country=’USA’, website=
>>> p2 = Publisher(name=”o’reilly”, address=’10 Fawcett St.’, city=’Cambridge’, state_province=’MA’, country=’USA’, website=
>>> publisher_list = Publisher.objects.all()
Publisher: Publisher object, Publisher: Publisher object
Yeehaa, let me know if you have any other questions!