#24264: foreign key constraint error migrating integer pk to CharField
----------------------------+-------------------------------------
Reporter: timgraham | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8alpha1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+-------------------------------------
Changes (by MarkusH):
* cc: MarkusH (added)
* stage: Unreviewed => Accepted
Comment:
Although I haven't tried to reproduce this particular issue, I wouldn't be
surprised if this is related to #24241
A brief discussion on IRC mentioned this traceback:
{{{#!python
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/tim/code/django/django/core/management/__init__.py", line
338, in execute_from_command_line
utility.execute()
File "/home/tim/code/django/django/core/management/__init__.py", line
330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/tim/code/django/django/core/management/commands/test.py",
line 30, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/home/tim/code/django/django/core/management/base.py", line 390,
in run_from_argv
self.execute(*args, **cmd_options)
File "/home/tim/code/django/django/core/management/commands/test.py",
line 74, in execute
super(Command, self).execute(*args, **options)
File "/home/tim/code/django/django/core/management/base.py", line 441,
in execute
output = self.handle(*args, **options)
File "/home/tim/code/django/django/core/management/commands/test.py",
line 90, in handle
failures = test_runner.run_tests(test_labels)
File "/home/tim/code/django/django/test/runner.py", line 210, in
run_tests
old_config = self.setup_databases()
File "/home/tim/code/django/django/test/runner.py", line 166, in
setup_databases
**kwargs
File "/home/tim/code/django/django/test/runner.py", line 370, in
setup_databases
serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE",
True),
File "/home/tim/code/django/django/db/backends/base/creation.py", line
369, in create_test_db
test_flush=True,
File "/home/tim/code/django/django/core/management/__init__.py", line
120, in call_command
return command.execute(*args, **defaults)
File "/home/tim/code/django/django/core/management/base.py", line 441,
in execute
output = self.handle(*args, **options)
File "/home/tim/code/django/django/core/management/commands/migrate.py",
line 213, in handle
executor.migrate(targets, plan, fake=options.get("fake", False))
File "/home/tim/code/django/django/db/migrations/executor.py", line 93,
in migrate
self.apply_migration(states[migration], migration, fake=fake)
File "/home/tim/code/django/django/db/migrations/executor.py", line 129,
in apply_migration
state = migration.apply(state, schema_editor)
File "/home/tim/code/django/django/db/migrations/migration.py", line
110, in apply
operation.database_forwards(self.app_label, schema_editor, old_state,
project_state)
File "/home/tim/code/django/django/db/migrations/operations/fields.py",
line 200, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "/home/tim/code/django/django/db/backends/base/schema.py", line
484, in alter_field
old_db_params, new_db_params, strict)
File "/home/tim/code/django/django/db/backends/base/schema.py", line
633, in _alter_field
params,
File "/home/tim/code/django/django/db/backends/base/schema.py", line
107, in execute
cursor.execute(sql, params)
File "/home/tim/code/django/django/db/backends/utils.py", line 65, in
execute
return self.cursor.execute(sql, params)
File "/home/tim/code/django/django/db/utils.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/tim/code/django/django/db/backends/utils.py", line 65, in
execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: foreign key constraint
"fundrais_donor_id_50d7dcbcff28bd90_fk_fundraising_djangohero_id" cannot
be implemented
DETAIL: Key columns "donor_id" and "id" are of incompatible types:
integer and character varying.
}}}
and this SQL
{{{#!sql
BEGIN;
ALTER TABLE "fundraising_donation" DROP CONSTRAINT
"fundraising_donation_donor_id_50d7dcbcff28bd90_fk";
ALTER TABLE "fundraising_djangohero" ALTER COLUMN "id" TYPE varchar(12);
ALTER TABLE "fundraising_donation" ALTER COLUMN "donor_id" TYPE
varchar(12);
ALTER TABLE "fundraising_donation" ADD CONSTRAINT
"fundraising_donation_donor_id_50d7dcbcff28bd90_fk" FOREIGN KEY
("donor_id") REFERENCES "fundraising_djangohero" ("id") DEFERRABLE
INITIALLY DEFERRED;
}}}
The interesting part is the difference between the constraint names.
--
Ticket URL: <https://code.djangoproject.com/ticket/24264#comment:1>
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/067.26e271730fdd677dd449eb7d7a1240dd%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.