Skip to content Skip to sidebar Skip to footer

Why Is Django Manytomanyfield Causing Admin Interface To Crash? Why Is No Through Table Being Created?

Why is this line users_favorited_by = models.ManyToManyField('auth.User') or this one, which causes the same error: users_favorited_by = models.ManyToManyField(User) in this mode

Solution 1:

I think your database is in an inconsistent state through all this commenting/migrating/uncommenting. Try dropping your db completely, deleting your migration files, and running makemigrations and migrate again.

Solution 2:

This is how I executed @DanielRoseman's advice, using two shells to my Ubuntu machine, both starting in the "main" user's command prompt:

  1. First, delete all "000*" files from /home/jeffy/django_files/django_test/billyjoel/migrations and /home/jeffy/django_files/django_test/billyjoel/migrations/__pycache__
  2. Shell one
    1. sudo su - postgres
    2. postgres command prompt:
      1. dropdb django_test_db
      2. createdb django_test_db
      3. psql django_test_db
      4. \dt public.* (should display no tables)
  3. Shell two
    1. source /home/jeffy/django_files/django_test_venv/bin/activate
    2. cd /home/jeffy/django_files/django_test (the directory containing manage.py)
    3. python manage.py makemigrations
    4. python manage.py migrate
  4. Shell one:
    1. Verify it worked with
      1. psql django_test_db
      2. \dt public.* (should display your Django tables)

Post a Comment for "Why Is Django Manytomanyfield Causing Admin Interface To Crash? Why Is No Through Table Being Created?"