Django : ProgrammingError: column "id" does not exist
<p>I try to use postgresql database (before I had SQLite) but I have a message when I execute <code>python manage.py migrate</code> :</p>

<pre><code>Operations to perform:
Apply all migrations: sessions, admin, sites, auth, contenttypes, main_app
Running migrations:
Rendering model states... DONE
Applying main_app.0004_auto_20161002_0034...Traceback (most recent call last):
File "manage.py", line 10, in &lt;module&gt;
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 345, 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 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/migrate.py", line 200, in handle
executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 92, in migrate
self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 121, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 198, in apply_migration
state = migration.apply(state, schema_editor)
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/migration.py", line 123, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/operations/fields.py", line 201, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/schema.py", line 482, in alter_field
old_db_params, new_db_params, strict)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/postgresql/schema.py", line 110, in _alter_field
new_db_params, strict,
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/schema.py", line 634, in _alter_field
params,
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/schema.py", line 110, in execute
cursor.execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
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 95, 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 64, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: column "id" does not exist
LINE 1: ..._app_projet" ALTER COLUMN "id" TYPE integer USING "id"::inte...
</code></pre>

<p>So I guess this error is about my model 'Projet' but this model has ID field ! I see that in <strong>0001_initial.py</strong> :</p>

<pre><code>...
migrations.CreateModel(
        name='Projet',
        fields=[
            ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
            ('name', models.CharField(db_index=True, max_length=30)),
            ('presentation', models.TextField(max_length=2500, null=True)),
...
</code></pre>

<p>My migration main_app.0004_auto_20161002_0034 :</p>

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

    dependencies = [
        ('main_app', '0003_auto_20161002_0033'),
    ]

    operations = [
        migrations.AlterField(
            model_name='projet',
            name='id',
            field=models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
    ),
    ]
</code></pre>

<p>Projet model is like that :</p>

<pre><code>class Group(models.Model) :
    name = models.CharField(max_length=30, db_index=True)

    class Meta :
        abstract = True
        unique_together = (("id", "name"),)


class Projet(Group) :
    presentation = models.TextField(max_length=2500, null=True)
</code></pre>

<p>Realy I don't understand why I have this error... my settings configuration database is good, all others models work, ...</p>

<p>If I forgot something, please don't hesitate to tell me ! I need realy your helps !</p>

<pre><code>class Group(models.Model) :
    name = models.CharField(max_length=30, unique=True)

    class Meta:
        abstract = True


class Projet(Group) :
    presentation = models.CharField(max_length=2500, blank=True)  
</code></pre>

<p>Remove your migration and create a new one.</p>

<p>Just adding my two cents. </p>

<p>Nullable fields:</p>

<blockquote>
  <p>Avoid using null on string-based fields such as CharField and
  TextField because empty string values will always be stored as empty
  strings, not as NULL. If a string-based field has null=True, that
  means it has two possible values for âno dataâ: NULL, and the empty
  string. In most cases, itâs redundant to have two possible values for
  âno data;â the Django convention is to use the empty string, not NULL.</p>
  
  <p>See <a href="https://docs.djangoproject.com/en/1.10/ref/models/fields/#null" rel="nofollow">https://docs.djangoproject.com/en/1.10/ref/models/fields/#null</a></p>
</blockquote>

<p>max_length:</p>

<blockquote>
  <p>If you specify a max_length attribute, it will be reflected in the
  Textarea widget of the auto-generated form field. However it is not
  enforced at the model or database level. Use a CharField for that.</p>
  
  <p><a href="https://docs.djangoproject.com/en/1.10/ref/models/fields/#textfield" rel="nofollow">https://docs.djangoproject.com/en/1.10/ref/models/fields/#textfield</a></p>
</blockquote>

python django postgresql