4

I am using django 1.8.2 and suddenly i can't use migrate anymore.

i searched a lot and found this post suggesting that i should remove name from django_content_type table. but that column is not in django_content_type table.

here is my django_content_type table:

 id |     app_label     |     model      
----+-------------------+----------------
  1 | admin             | logentry
  2 | auth              | permission
  3 | auth              | group
  4 | auth              | user
  5 | contenttypes      | contenttype
  6 | sessions          | session
  7 | centuryPhotograph | temporaryuser
  8 | centuryPhotograph | userinfo
  9 | centuryPhotograph | log
 10 | centuryPhotograph | uploadedimages
(10 rows)

here is complete error:

System check identified some issues:

WARNINGS:
centuryPhotograph.Galleries.closed: (1_6.W002) BooleanField does not have a default value.
    HINT: Django 1.6 changed the default value of BooleanField from False to None. See https://docs.djangoproject.com/en/1.6/ref/models/fields/#booleanfield for more information.
centuryPhotograph.Galleries.open_gallery: (1_6.W002) BooleanField does not have a default value.
    HINT: Django 1.6 changed the default value of BooleanField from False to None. See https://docs.djangoproject.com/en/1.6/ref/models/fields/#booleanfield for more information.
Operations to perform:
  Apply all migrations: admin, centuryPhotograph, contenttypes, auth, sessions
Running migrations:
  No migrations to apply.
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 385, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/migrate.py", line 165, in handle
    emit_post_migrate_signal(created_models, self.verbosity, self.interactive, connection.alias)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/sql.py", line 268, in emit_post_migrate_signal
    using=db)
  File "/usr/local/lib/python2.7/dist-packages/django/dispatch/dispatcher.py", line 198, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/management/__init__.py", line 83, in create_permissions
    ctype = ContentType.objects.db_manager(using).get_for_model(klass)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/contenttypes/models.py", line 58, in get_for_model
    " is migrated before trying to migrate apps individually."
RuntimeError: Error creating new content types. Please make sure contenttypes is migrated before trying to migrate apps individually.

here is my installed_apps:

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'centuryPhotograph',
)

i removed all migrations once and tried migrating, but problem is still there.

Community
  • 1
  • 1
samad montazeri
  • 1,203
  • 16
  • 28
  • 4
    Try migrating just the contenttypes app with `./manage.py migrate contenttypes`. – Alasdair Sep 10 '15 at 13:26
  • 2
    thanks. that did something(i don't know what!). the error is gone. i can do `makemigrations` and `migrate` without any error. but migrations wont apply :( – samad montazeri Sep 10 '15 at 15:03
  • 1
    I'm not sure what you mean by "won't apply". What are the contents of the migrations that "won't apply". What is the output of `./manage.py showmigrations`? Does that match the contents of the db when you do `select * from django_migrations;` – Alasdair Sep 10 '15 at 15:09

1 Answers1

2

I am on Django 1.9 and faced the same problem.The solution posted in the comments above did not work for me, so posting what worked for me:

  1. Remove all migrations folders from all the apps.
  2. Run python manage.py migrate
  3. Run python manage.py makemigrations
  4. Run python manage.py migrate

The key here is to run migrate once before you run makemigrations.

This will run migrations on all default models of Django for models like: contenttypes, admin, sites, auth, sessions etc.

Once this is done, you run makemigrations which makes migrations for your custom defined models for your project.

Finally when you run migrate once again, it migrates all your custom models and does not complain of no migrations run on contenttype.

bhaskarc
  • 9,269
  • 10
  • 65
  • 86