Reputation: 359
Going through Django tutorial 1 using Python 2.7 and can't seem to resolve this error: OperationalError: no such table: polls_poll
This happens the moment I enter Poll.objects.all()
into the shell.
Things I've already tried based on research through the net:
1) Ensured that 'polls'
is listed under INSTALLED_APPS
in settings.py
Note: I've seen lots of suggestions inserting 'mysite.polls'
instead of 'polls'
into INSTALLED_APPS
but this gives the following error: ImportError: cannot import name 'polls' from 'mysite'
2) Run python manage.py syncdb
. This creates my db.sqlite3 file successfully and seemingly without issue in my mysite folder.
3) Finally, when I run python manage.py shell
, the shell runs smoothly, however I do get some weird Runtime Warning when it starts and wonder if the polls_poll error is connected:
\django\db\backends\sqlite3\base.py:63: RuntimeWarning: SQLite received a naive datetime (2014-02-03 17:32:24.392000) while time zone support is active.
Any help would be appreciated.
Upvotes: 5
Views: 14454
Reputation: 837
I've just solved this problem in a very easy and effective way.
This error is coming because of wrong pycache and db.sqlite3 in django To solve this error we can delete those files and re-make it.
Delete pycache and db.sqlite3 manually.
then run this in terminal:
python manage.py makemigrations polls
After this your database and __pycache will be created again. And just make migrations, it will work fine.
Of course you might want to store your data before deleting database.
Upvotes: 2
Reputation: 951
For those encountering this error in the current django 3.0 release (https://docs.djangoproject.com/en/3.0/intro/tutorial02/), you can rectify it by making sure you've run the following commands in order.
python manage.py makemigrations polls
python manage.py sqlmigrate polls 0001
python manage.py migrate
Upvotes: 2
Reputation: 147
i figured out the mistake you did, after making changes to your models.py you should run migrate ..i.e
python manage.py migrate
then only your changes(polls_question) will be visible
Upvotes: 9
Reputation: 176
I meet the same problem today and fix it I think you miss some command in tutorial 1 just do follow:
./python manage.py makemigrations polls
python manage.py sql polls
./python manage.py syncdb
then fix it and gain the table polls and you can see the table created you should read the "manage.py makemigrations" command
Upvotes: 11