Getting DatabaseError: multiple default values specified for column Getting DatabaseError: multiple default values specified for column postgresql postgresql

Getting DatabaseError: multiple default values specified for column


You are anyways saying keep_default=False. So remove that default=0 from your code

   db.add_column(u'tagplus', u'id',                  self.gf('django.db.models.fields.AutoField')(primary_key=True),                  keep_default=False)

Per SQL it should be (remove the NOT NULL)

ALTER TABLE tagplus ADD COLUMN id serial PRIMARY KEY

See this document which explains the reason behind this error http://www.postgresql.org/docs/8.3/interactive/datatype-numeric.html#DATATYPE-SERIAL


There are two things to note:

  1. Django will use 'id' as the default primary key if you haven't manually set one before, see here.

  2. Postgres does not really have a 'serial' type. To resolve this issue, try to replace:

    # Adding field 'TagPlus.id'db.add_column(u'tagplus', u'id', self.gf('django.db.models.fields.AutoField')(default=0, primary_key=True), keep_default=False)

with:

    # Adding field 'TagPlus.id'    if 'postgres' in db.backend_name.lower():        db.execute("CREATE SEQUENCE tagplus_id_seq")        db.execute("SELECT setval('tagplus_id_seq', (SELECT MAX(id) FROM tagplus))")        db.execute("ALTER TABLE tagplus ADD COLUMN id SET DEFAULT nextval('tagplus_id_seq'::regclass)")        db.execute("ALTER SEQUENCE tagplus_id_seq OWNED BY tagplus.id")    else:        db.add_column(u'tagplus', u'id', self.gf('django.db.models.fields.AutoField')(default=0, primary_key=True), keep_default=False)