Django: python manage.py makemigrations returns IntegrityError: Column 'content_type_id' cannot be null
<p>I hooked up my Django project the the MySQL Database, and I am certain that it is actually connected because when I try to makemigrations. I checked MySQL workbench and all my models are synced into the database. However, the problem is when i try to migrate, I get this error. It is complaining that No migrations to apply because mysql.connector.errors.IntegrityError: 1048 (23000): Column 'content_type_id' cannot be null. I am not even sure where content_type_id is coming from because my model doesn't even have that. </p>

<pre><code>Operations to perform:
  Target specific migration: 0001_initial, from bookSell
Running migrations:
  No migrations to apply.
Traceback (most recent call last):
  File "/Users/JenniferLiu/.virtualenvs/bookSell/lib/python3.5/site-packages/mysql/connector/django/base.py", line 177, in _execute_wrapper
    return method(query, args)
  File "/Users/JenniferLiu/.virtualenvs/bookSell/lib/python3.5/site-packages/mysql/connector/cursor.py", line 515, in execute
    self._handle_result(self._connection.cmd_query(stmt))
  File "/Users/JenniferLiu/.virtualenvs/bookSell/lib/python3.5/site-packages/mysql/connector/connection.py", line 488, in cmd_query
    result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
  File "/Users/JenniferLiu/.virtualenvs/bookSell/lib/python3.5/site-packages/mysql/connector/connection.py", line 395, in _handle_result
    raise errors.get_exception(packet)
mysql.connector.errors.IntegrityError: 1048 (23000): Column 'content_type_id' cannot be null

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 10, in &lt;module&gt;
    execute_from_command_line(sys.argv)
  File "/Users/JenniferLiu/.virtualenvs/bookSell/lib/python3.5/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/Users/JenniferLiu/.virtualenvs/bookSell/lib/python3.5/site-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/JenniferLiu/.virtualenvs/bookSell/lib/python3.5/site-packages/django/core/management/base.py", line 294, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/JenniferLiu/.virtualenvs/bookSell/lib/python3.5/site-packages/django/core/management/base.py", line 345, in execute
    output = self.handle(*args, **options)
  File "/Users/JenniferLiu/.virtualenvs/bookSell/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line 224, in handle
    self.verbosity, self.interactive, connection.alias, apps=post_migrate_apps, plan=plan,
  File "/Users/JenniferLiu/.virtualenvs/bookSell/lib/python3.5/site-packages/django/core/management/sql.py", line 53, in emit_post_migrate_signal
    **kwargs
  File "/Users/JenniferLiu/.virtualenvs/bookSell/lib/python3.5/site-packages/django/dispatch/dispatcher.py", line 191, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/Users/JenniferLiu/.virtualenvs/bookSell/lib/python3.5/site-packages/django/contrib/auth/management/__init__.py", line 83, in create_permissions
    Permission.objects.using(using).bulk_create(perms)
  File "/Users/JenniferLiu/.virtualenvs/bookSell/lib/python3.5/site-packages/django/db/models/query.py", line 452, in bulk_create
    ids = self._batched_insert(objs_without_pk, fields, batch_size)
  File "/Users/JenniferLiu/.virtualenvs/bookSell/lib/python3.5/site-packages/django/db/models/query.py", line 1068, in _batched_insert
    self._insert(item, fields=fields, using=self.db)
  File "/Users/JenniferLiu/.virtualenvs/bookSell/lib/python3.5/site-packages/django/db/models/query.py", line 1045, in _insert
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/Users/JenniferLiu/.virtualenvs/bookSell/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 1054, in execute_sql
    cursor.execute(sql, params)
  File "/Users/JenniferLiu/.virtualenvs/bookSell/lib/python3.5/site-packages/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/Users/JenniferLiu/.virtualenvs/bookSell/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/Users/JenniferLiu/.virtualenvs/bookSell/lib/python3.5/site-packages/mysql/connector/django/base.py", line 227, in execute
    return self._execute_wrapper(self.cursor.execute, query, new_args)
  File "/Users/JenniferLiu/.virtualenvs/bookSell/lib/python3.5/site-packages/mysql/connector/django/base.py", line 183, in _execute_wrapper
    utils.IntegrityError(err.msg), sys.exc_info()[2])
  File "/Users/JenniferLiu/.virtualenvs/bookSell/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/Users/JenniferLiu/.virtualenvs/bookSell/lib/python3.5/site-packages/mysql/connector/django/base.py", line 177, in _execute_wrapper
    return method(query, args)
  File "/Users/JenniferLiu/.virtualenvs/bookSell/lib/python3.5/site-packages/mysql/connector/cursor.py", line 515, in execute
    self._handle_result(self._connection.cmd_query(stmt))
  File "/Users/JenniferLiu/.virtualenvs/bookSell/lib/python3.5/site-packages/mysql/connector/connection.py", line 488, in cmd_query
    result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
  File "/Users/JenniferLiu/.virtualenvs/bookSell/lib/python3.5/site-packages/mysql/connector/connection.py", line 395, in _handle_result
    raise errors.get_exception(packet)
django.db.utils.IntegrityError: Column 'content_type_id' cannot be null
</code></pre>

<p>Here is my model.py:</p>

<pre><code>class Book(models.Model):
    title = models.CharField(max_length=200,default='')
    author = models.CharField(max_length=200,default='')
    year_published = models.DateField(default='1998-09-18')
    description = models.CharField(max_length = 500,default='')
    rating = models.IntegerField(default=1)
</code></pre>

<p>This is migrations 0001_initial.py:</p>

<pre><code>class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Book',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('title', models.CharField(default='', max_length=200)),
                ('author', models.CharField(default='', max_length=200)),
                ('year_published', models.DateField(default='1998-09-18')),
                ('description', models.CharField(default='', max_length=500)),
                ('rating', models.IntegerField(default=1)),
            ],
        ),
    ]
</code></pre>

<p>python manage.py makemigrations worked fine. This was the result</p>

<pre><code>Migrations for 'bookSell':
  bookSell/migrations/0001_initial.py:
    - Create model Book
</code></pre>

<p>Much help is appreciated, thank you, please leave a comment if any additional information is needed to solve this problem. :D</p>

<p>EDIT 2
Setting.py </p>

<pre><code>INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'bookSell',
]
</code></pre>

<p>So I manage to get python to runserver, and in admin I do get it to run with the Books Model, but issue is that when i try to add books. I get the error, Column 'user_id' cannot be null</p>

<blockquote>
  <p>I am certain that it is actually connected because when I try to
  makemigrations. I checked MySQL workbench and all my models are synced
  into the database.</p>
</blockquote>

<p>It sounds more like you are connecting to a database that was already being used for something, or you have run <code>migrate</code> on this database before. <code>makemigrations</code> does not make any changes to the database. The only thing it does is to create a set of files in the migrations folder of your apps.</p>

<p>There could be several </p>

<p>The content_type_id comes from the <a href="https://docs.djangoproject.com/en/1.10/ref/contrib/contenttypes/" rel="nofollow">content types frame work</a> which means one of the libraries you are using probably uses a generic foreign key.</p>

<p>There are several things you could try, if this is a new installation without any data, just drop the database and start again.</p>

python mysql django