Given a newly created django project with the following installed apps:
INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'registration', )
When I run ./manage.py migrate for the first time I get the following error:
Operations to perform: Synchronize unmigrated apps: staticfiles, messages, registration Apply all migrations: sessions, admin, auth, contenttypes Synchronizing apps without migrations: Creating tables... Creating table registration_registrationprofile Running deferred SQL... Traceback (most recent call last): File "./manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/Users/tcosta/Virtualenvs/django_project/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line utility.execute() File "/Users/tcosta/Virtualenvs/django_project/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/Users/tcosta/Virtualenvs/django_project/lib/python2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv self.execute(*args, **cmd_options) File "/Users/tcosta/Virtualenvs/django_project/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute output = self.handle(*args, **options) File "/Users/tcosta/Virtualenvs/django_project/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 179, in handle created_models = self.sync_apps(connection, executor.loader.unmigrated_apps) File "/Users/tcosta/Virtualenvs/django_project/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 317, in sync_apps cursor.execute(statement) File "/Users/tcosta/Virtualenvs/django_project/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute return super(CursorDebugWrapper, self).execute(sql, params) File "/Users/tcosta/Virtualenvs/django_project/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute return self.cursor.execute(sql, params) File "/Users/tcosta/Virtualenvs/django_project/lib/python2.7/site-packages/django/db/utils.py", line 97, in __exit__ six.reraise(dj_exc_type, dj_exc_value, traceback) File "/Users/tcosta/Virtualenvs/django_project/lib/python2.7/site-packages/django/db/backends/utils.py", line 62, in execute return self.cursor.execute(sql) django.db.utils.ProgrammingError: relation "auth_user" does not exist```
It seems Django is trying to create the registration tables before the user table.
This erros does not happen if I comment the registration app and run migrate and then uncomment the registration app and run migrate again. However, that's not the right way of doing it, right?
registrationmigration could probably use a
auth.User. Since it's a library, I'm not really sure what the solution is here. Perhaps the order of
python manage.py migratemigrates all apps in correct order with auth first on mysql5.6 but when I move to mysql5.7, I see this issue.
I had this problem too, solved it by replacing old registration with one that includes pull #25:
pip install git+https://email@example.com
In my case, this has been resolved re-adding some modules in INSTALLED_APPS that had been removed. As a consequence, some tables in the database were confusing the migration scheme and then ruining the
test command because the default database was containing those previous migrations.
Fixed re-adding the modules,
allauth and other related submodules in my case.
Once you create a migration for your app it will automatically add the necessary dependencies. So in this case just run
./manage.py makemigrations registration.
Please check the registration/migrations/0001_initial.py file and you should see something like this:
dependencies = [ migrations.swappable_dependency(settings.AUTH_USER_MODEL), ]
This means you need to create migrations for all your apps with any kind of dependency.
I think you needed to run:
python manage.py syncdb
and potentially you need to setup some dependencies? Probably not necessary after syncdb.
class Migration: depends_on = ( ("accounts", "0001"), ) def forwards(self): ....
from django.db import migrations, models class Migration(migrations.Migration): dependencies = [("accounts", "0001")]
After updating my Django version, I got this error and fix as running these two lines:
python manage.py migrate auth python manage.py migrate
auth_user table inside auth model should run first I guess.
manage migratebut this is the first I've seen that mentions
manage migrate auth. Is this due to originating my app with Django 1.6 and upgrading along the way to 2.0 now? Or are most of these answers just incomplete?
The problem is avoided when you do as Pedro Wagner suggests (auth_user error with Django 1.8 and syncdb / migrate):
Make sure that for all your apps, there exist initial migrations files by running:
manage.py makemigrations my_app
I'd do it not only for those that depend on auth because I think the problem is more general.
The root cause for this behaviour seems to me that for some reason
does not always create the initial migrations if they are not already there, contrary to:
manage.py makemigrations my_app
Unfortunately I cannot fathom the reasons for this asymmetry.
you have not migrated your models
python manage.py makemigrations my_app_name
for mac os
python3 manage.py makemigrations my_app
I think you just forgot to migrate your auth models. However, to do that, just type in the following command on your terminal.
python manage.py migrate
python manage.py migrate auth
Hope this settles your error in the program.