Django 1.7.1, MySQL 5.6, Python 2.7.8
I had a model that looked like this:
class Host(models.Model):
hostName = models.CharField(max_length=45, primary_key=True)
...
I deleted it primary_key=Truemanually, which made it manage.py sqlmigrateshow that the primary key was deleted, an auto-increment column was added 'id', and it gets the primary key. I was offered the default value for the new column 'id'and mistakenly gave it 1, which was already in the table. Corresponding SQL:
ALTER TABLE `Host` ADD COLUMN `id` integer AUTO_INCREMENT DEFAULT 1 NOT NULL PRIMARY KEY;
and migration code:
operations = [
migrations.AddField(
model_name='host',
name='id',
field=models.AutoField(auto_created=True, primary_key=True, default=1, serialize=False, verbose_name='ID'),
preserve_default=False,
),
As a result, I can still change my models and it makemigrationsworks, but each command migrategives this error:
django.db.utils.OperationalError: (1067, "Invalid default value for 'id'")
and does not enter into force.
, ( ) . , / . , . ?
Edit:
, , Django SQL ...AUTO_INCREMENT DEFAULT 1...?