python - Django ManyToMany Relation with django.contrib.auth.models.User -


i have following model:

class bm(models.model):     created_date = models.datetimefield(auto_now_add=true, editable=false)     birth_date = models.datetimefield(null=false, blank=false)     name = models.charfield(null=false, blank=false, max_length = 255)     relations = models.manytomanyfield(user) 

when try run test python manage.py test following error:

django.db.utils.programmingerror: relation "auth_user" not exist

this due trying create relation user table before table gets created itself.

how can this?

edited say:

this happening because bm model table being created before auth user table, following statement run (according ./manage sqlall p:

create table "p_baby_relations" (     "id" serial not null primary key,     "baby_id" integer not null,     "user_id" integer not null references "auth_user" ("id") deferrable deferred,     unique ("baby_id", "user_id") ) ; 

the error because of not null references "auth_user" means auth user table has not been created.

stack trace:

traceback (most recent call last):   file "manage.py", line 10, in <module>     execute_from_command_line(sys.argv)   file "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line     utility.execute()   file "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 330, in execute     self.fetch_command(subcommand).run_from_argv(self.argv)   file "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/test.py", line 30, in run_from_argv     super(command, self).run_from_argv(argv)   file "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 390, in run_from_argv     self.execute(*args, **cmd_options)   file "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/test.py", line 74, in execute     super(command, self).execute(*args, **options)   file "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 441, in execute     output = self.handle(*args, **options)   file "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/test.py", line 90, in handle     failures = test_runner.run_tests(test_labels)   file "/usr/local/lib/python2.7/dist-packages/django/test/runner.py", line 210, in run_tests     old_config = self.setup_databases()   file "/usr/local/lib/python2.7/dist-packages/django/test/runner.py", line 166, in setup_databases     **kwargs   file "/usr/local/lib/python2.7/dist-packages/django/test/runner.py", line 370, in setup_databases     serialize=connection.settings_dict.get("test", {}).get("serialize", true),   file "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/creation.py", line 368, in create_test_db     test_flush=not keepdb,   file "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 120, in call_command     return command.execute(*args, **defaults)   file "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 441, in execute     output = self.handle(*args, **options)   file "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/migrate.py", line 179, in handle     created_models = self.sync_apps(connection, executor.loader.unmigrated_apps)   file "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/migrate.py", line 317, in sync_apps     cursor.execute(statement)   file "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 64, in execute     return self.cursor.execute(sql, params)   file "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 97, in __exit__     six.reraise(dj_exc_type, dj_exc_value, traceback)   file "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 62, in execute     return self.cursor.execute(sql) django.db.utils.programmingerror: relation "auth_user" not exist 

you need specify auth.user dependency in migration.

class migration(migrations.migration):     dependencies = [         ('user', '0001_initial'),     ] 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -