#27267: Renaming a primary key fails with "cannot drop constraint on table
because
other objects depend on it"
--------------------------------+--------------------------------------
Reporter: Melvyn Sopacua | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------
Changes (by Melvyn Sopacua):
* status: closed => new
* resolution: needsinfo =>
Comment:
I'm not able to reproduce but closer to the cause.
I cannot save an instance of the model referenced 'dpecharacter' - this is
the initial model that had a varchar primary key that I dropped. When I
try to save a model I run into an integrity error for the id field (the
autogenerated id). I checked and the sequence has correctly been created
(postgres) as `dpe_dpecharacter_id_seq` in the public schema, but
apparently isn't consulted.
When I try to regenrate the autofield, using a named auto field,
makemigrations provides me with the "null field but no default" prompt.
When I give a one-off default, `migrate` gives me:
{{{
django.db.utils.ProgrammingError: multiple default values specified for
column "character_id" of table "dpe_dpecharacter"
}}}
The field declaration is: `character_id =
models.AutoField(primary_key=True)`. The migration code is:
{{{#!python
# -*- coding: utf-8 -*-
# Generated by Django 1.10.1 on 2016-10-07 12:53
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dpe', '0012_incubatorspot_destined_for'),
]
operations = [
migrations.RemoveField(
model_name='dpecharacter',
name='id',
),
migrations.AddField(
model_name='dpecharacter',
name='character_id',
field=models.AutoField(default=0, primary_key=True,
serialize=False),
preserve_default=False,
),
]
}}}
When I remove the default=0 argument from the field declaration, the
migration goes through.
The old sequence has been dropped and the new one created with the correct
name. Yet, once again I run into the integrity error, this time for the
new field name "character_id".
Two problems here:
1. I don't know **how** I got into this situation.
2. I don't seem to be able to get out of it.
What should I be looking for as to why the serial isn't being consulted?
--
Ticket URL: <https://code.djangoproject.com/ticket/27267#comment:9>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/072.759c8de87c74340ffdaefdb1ce9de6b0%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.