encode/rest-framework-tutorial

Error during initial DB migration

austinnichols101 opened this issue · 8 comments

Getting this message when attempting to run manage.py migrate:

django.db.utils.OperationalError: Problem installing fixture '/home/foo/rest-framework-tutorial/rest-framework-tutorial/snippets/fixtures/initial_data.json': Could not load auth.User(pk=2): no such table: auth_user

Same result if I remove the included tmp.db and allowing the app to create a fresh db.

Traceback (most recent call last):
File "/home/foo/rest-framework-tutorial/venv/lib/python3.4/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/home/foo/rest-framework-tutorial/venv/lib/python3.4/site-packages/django/db/backends/sqlite3/base.py", line 485, in execute
return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: no such table: auth_user

The above exception was the direct cause of the following exception:

tcab commented

I'm getting a similar problem when I run manage.py migrate as well.

django.db.utils.OperationalError: Problem installing fixture '/Users/.../rest3-framework-tutorial/snippets/fixtures/initial_data.json': Could not load auth.User(pk=2): no such table: auth_user

Running locally, with the correct versions of libraries.

To fix it I edited rest-framework-tutorial/tutorial/settings.py INSTALLED_APPS and uncommented 'django.contrib.admin', and temporarily commented out 'snippets', then I ran manage.py syncdb which correctly created the admin tables. Then I re-edited and uncommented 'snippets', and ran syncdb again. That fixed the problem. There may be a better way but it got me going.

I think that the exact problem here is that the fixtures in the snippets add contain data for models that are not included in this app. So most probably manage.py migrate creates the tables for snippets before creating the tables for users, despite snippets depend on users.

Maybe the cleaner solution would be creating a custom user model in a new Django app and adding the fixtures there, while replacing auth.user with the new user model class.

Maybe we should ask @tomchristie if he would be welcoming a pull request for this. I would be more than happy to do this.

Not convinced we should have any fixtures.

Removing them would resolve the issue, so...

👍

We could also just change the name in order to avoid having them installed automatically, but letting the users load them using manage.py loaddata.

Also possible. PRs along these lines would be considered, yup.

Closed by #21