#26054: Migrations work on Django 1.9.0 but not on Django 1.9.1
-----------------------------------+------------------------
Reporter: grantmcconnaughey | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.9
Severity: Normal | Keywords: migrations
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------
I have two migrations in an app. They work on Django 1.9.0, but when I
upgrade to 1.9.1 they fail. It looks like an issue with altering the field
`'name'` in the second migration. When I comment out the
`migrations.AlterField` for `'name'`, the migrations work.
I'm using Django 1.9.1, Python 2.7.6, and PostgreSQL 9.3.
Here's the failure traceback:
{{{
Traceback (most recent call last):
File "./manage.py", line 12, in <module>
execute_from_command_line(sys.argv)
File "/home/vagrant/.virtualenvs/django_1_9/local/lib/python2.7/site-
packages/django/core/management/__init__.py", line 353, in
execute_from_command_line
utility.execute()
File "/home/vagrant/.virtualenvs/django_1_9/local/lib/python2.7/site-
packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/vagrant/.virtualenvs/django_1_9/local/lib/python2.7/site-
packages/django/core/management/commands/test.py", line 30, in
run_from_argv
super(Command, self).run_from_argv(argv)
File "/home/vagrant/.virtualenvs/django_1_9/local/lib/python2.7/site-
packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/vagrant/.virtualenvs/django_1_9/local/lib/python2.7/site-
packages/django/core/management/commands/test.py", line 74, in execute
super(Command, self).execute(*args, **options)
File "/home/vagrant/.virtualenvs/django_1_9/local/lib/python2.7/site-
packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/home/vagrant/.virtualenvs/django_1_9/local/lib/python2.7/site-
packages/django/core/management/commands/test.py", line 90, in handle
failures = test_runner.run_tests(test_labels)
File "/home/vagrant/.virtualenvs/django_1_9/local/lib/python2.7/site-
packages/django/test/runner.py", line 532, in run_tests
old_config = self.setup_databases()
File "/home/vagrant/.virtualenvs/django_1_9/local/lib/python2.7/site-
packages/django/test/runner.py", line 482, in setup_databases
self.parallel, **kwargs
File "/home/vagrant/.virtualenvs/django_1_9/local/lib/python2.7/site-
packages/django/test/runner.py", line 726, in setup_databases
serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE",
True),
File "/home/vagrant/.virtualenvs/django_1_9/local/lib/python2.7/site-
packages/django/db/backends/base/creation.py", line 70, in create_test_db
run_syncdb=True,
File "/home/vagrant/.virtualenvs/django_1_9/local/lib/python2.7/site-
packages/django/core/management/__init__.py", line 119, in call_command
return command.execute(*args, **defaults)
File "/home/vagrant/.virtualenvs/django_1_9/local/lib/python2.7/site-
packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/home/vagrant/.virtualenvs/django_1_9/local/lib/python2.7/site-
packages/django/core/management/commands/migrate.py", line 200, in handle
executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
File "/home/vagrant/.virtualenvs/django_1_9/local/lib/python2.7/site-
packages/django/db/migrations/executor.py", line 92, in migrate
self._migrate_all_forwards(plan, full_plan, fake=fake,
fake_initial=fake_initial)
File "/home/vagrant/.virtualenvs/django_1_9/local/lib/python2.7/site-
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 "/home/vagrant/.virtualenvs/django_1_9/local/lib/python2.7/site-
packages/django/db/migrations/executor.py", line 198, in apply_migration
state = migration.apply(state, schema_editor)
File "/home/vagrant/.virtualenvs/django_1_9/local/lib/python2.7/site-
packages/django/db/migrations/migration.py", line 123, in apply
operation.database_forwards(self.app_label, schema_editor, old_state,
project_state)
File "/home/vagrant/.virtualenvs/django_1_9/local/lib/python2.7/site-
packages/django/db/migrations/operations/fields.py", line 201, in
database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "/home/vagrant/.virtualenvs/django_1_9/local/lib/python2.7/site-
packages/django/db/backends/base/schema.py", line 482, in alter_field
old_db_params, new_db_params, strict)
File "/home/vagrant/.virtualenvs/django_1_9/local/lib/python2.7/site-
packages/django/db/backends/postgresql/schema.py", line 116, in
_alter_field
self.execute(like_index_statement)
File "/home/vagrant/.virtualenvs/django_1_9/local/lib/python2.7/site-
packages/django/db/backends/base/schema.py", line 110, in execute
cursor.execute(sql, params)
File "/home/vagrant/.virtualenvs/django_1_9/local/lib/python2.7/site-
packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/home/vagrant/.virtualenvs/django_1_9/local/lib/python2.7/site-
packages/django/db/utils.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/vagrant/.virtualenvs/django_1_9/local/lib/python2.7/site-
packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation
"managementcompany_managementcompany_name_65f40765_like" already exist
}}}
Below are the two migrations.
{{{
#!python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import django_extensions.db.fields
import django.utils.timezone
from django.conf import settings
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='Client',
fields=[
('id', models.AutoField(verbose_name='ID',
serialize=False, auto_created=True, primary_key=True)),
('date_created',
django_extensions.db.fields.CreationDateTimeField(default=django.utils.timezone.now,
editable=True, blank=True)),
('date_updated',
django_extensions.db.fields.ModificationDateTimeField(default=django.utils.timezone.now,
editable=True, blank=True)),
('name', models.CharField(unique=True, max_length=75)),
('address', models.ForeignKey(blank=True,
to='location.Address', null=True)),
('created_by', models.ForeignKey(related_name='+',
blank=True, to=settings.AUTH_USER_MODEL, null=True)),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='ClientCompany',
fields=[
('id', models.AutoField(verbose_name='ID',
serialize=False, auto_created=True, primary_key=True)),
('date_created',
django_extensions.db.fields.CreationDateTimeField(default=django.utils.timezone.now,
editable=True, blank=True)),
('date_updated',
django_extensions.db.fields.ModificationDateTimeField(default=django.utils.timezone.now,
editable=True, blank=True)),
('name', models.CharField(unique=True, max_length=75)),
('incorporation_date', models.DateField(null=True,
blank=True)),
('company_type', models.CharField(max_length=1,
choices=[(b'R', b'Reinsurance'), (b'E', b'Exempt'), (b'O',
b'Ordinary')])),
('status', models.CharField(max_length=1, choices=[(b'A',
b'Active')])),
('registration_number', models.CharField(max_length=100,
null=True, blank=True)),
('annual_Fee', models.DecimalField(null=True,
max_digits=12, decimal_places=2, blank=True)),
('notes', models.TextField(null=True, blank=True)),
('address', models.ForeignKey(blank=True,
to='location.Address', null=True)),
('client', models.ForeignKey(related_name='companies',
blank=True, to='managementcompany.Client', null=True)),
('created_by', models.ForeignKey(related_name='+',
blank=True, to=settings.AUTH_USER_MODEL, null=True)),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='ClientShareholder',
fields=[
('id', models.AutoField(verbose_name='ID',
serialize=False, auto_created=True, primary_key=True)),
('date_created',
django_extensions.db.fields.CreationDateTimeField(default=django.utils.timezone.now,
editable=True, blank=True)),
('date_updated',
django_extensions.db.fields.ModificationDateTimeField(default=django.utils.timezone.now,
editable=True, blank=True)),
('name', models.CharField(max_length=255)),
('shares', models.IntegerField(null=True, blank=True)),
('ownership_percent', models.IntegerField(default=0)),
('relationship', models.CharField(max_length=50,
null=True, blank=True)),
('primary_rank', models.CharField(max_length=1, null=True,
choices=[(b'', b'----------'), (b'D', b'Director'), (b'O', b'Officer'),
(b'P', b'President'), (b'S', b'Secretary'), (b'T', b'Treasurer'), (b'V',
b'Vice President')])),
('secondary_rank', models.CharField(blank=True,
max_length=1, null=True, choices=[(b'', b'----------'), (b'D',
b'Director'), (b'O', b'Officer'), (b'P', b'President'), (b'S',
b'Secretary'), (b'T', b'Treasurer'), (b'V', b'Vice President')])),
('type', models.CharField(max_length=1, null=True,
choices=[(b'C', b'Corporation'), (b'I', b'Individual'), (b'L', b'LLC'),
(b'T', b'Trust')])),
('board_member', models.BooleanField(default=False)),
('address', models.ForeignKey(blank=True,
to='location.Address', null=True)),
('client_company',
models.ForeignKey(related_name='shareholders',
to='managementcompany.ClientCompany')),
('created_by', models.ForeignKey(related_name='+',
blank=True, to=settings.AUTH_USER_MODEL, null=True)),
('phone', models.ForeignKey(blank=True,
to='location.Phone', null=True)),
('updated_by', models.ForeignKey(related_name='+',
blank=True, to=settings.AUTH_USER_MODEL, null=True)),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='ManagementCompany',
fields=[
('id', models.AutoField(verbose_name='ID',
serialize=False, auto_created=True, primary_key=True)),
('date_created',
django_extensions.db.fields.CreationDateTimeField(default=django.utils.timezone.now,
editable=True, blank=True)),
('date_updated',
django_extensions.db.fields.ModificationDateTimeField(default=django.utils.timezone.now,
editable=True, blank=True)),
('can_login', models.BooleanField(default=True)),
('name', models.CharField(unique=True, max_length=75)),
('address', models.ForeignKey(blank=True,
to='location.Address', null=True)),
('created_by', models.ForeignKey(related_name='+',
blank=True, to=settings.AUTH_USER_MODEL, null=True)),
('phone', models.ForeignKey(blank=True,
to='location.Phone', null=True)),
('updated_by', models.ForeignKey(related_name='+',
blank=True, to=settings.AUTH_USER_MODEL, null=True)),
],
options={
'verbose_name': 'managementcompany',
'verbose_name_plural': 'managementcompanies',
},
),
migrations.AddField(
model_name='clientcompany',
name='management_company',
field=models.ForeignKey(related_name='client_companies',
to='managementcompany.ManagementCompany'),
),
migrations.AddField(
model_name='clientcompany',
name='phone',
field=models.ForeignKey(blank=True, to='location.Phone',
null=True),
),
migrations.AddField(
model_name='clientcompany',
name='updated_by',
field=models.ForeignKey(related_name='+', blank=True,
to=settings.AUTH_USER_MODEL, null=True),
),
migrations.AddField(
model_name='client',
name='management_company',
field=models.ForeignKey(related_name='clients',
to='managementcompany.ManagementCompany'),
),
migrations.AddField(
model_name='client',
name='phone',
field=models.ForeignKey(blank=True, to='location.Phone',
null=True),
),
migrations.AddField(
model_name='client',
name='updated_by',
field=models.ForeignKey(related_name='+', blank=True,
to=settings.AUTH_USER_MODEL, null=True),
),
]
}}}
{{{
#!python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('location', '0001_initial'),
('managementcompany', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='managementcompany',
name='account_number',
field=models.CharField(db_index=True, max_length=50,
blank=True),
),
migrations.AddField(
model_name='managementcompany',
name='customer_id',
field=models.CharField(max_length=20, null=True, blank=True),
),
migrations.AddField(
model_name='managementcompany',
name='dba',
field=models.CharField(max_length=255, blank=True),
),
migrations.AddField(
model_name='managementcompany',
name='fax',
field=models.ForeignKey(related_name='+', blank=True,
to='location.Phone', null=True),
),
migrations.AddField(
model_name='managementcompany',
name='qb_customer_id',
field=models.IntegerField(null=True, blank=True),
),
migrations.AddField(
model_name='managementcompany',
name='qb_vendor_id',
field=models.IntegerField(null=True, blank=True),
),
migrations.AddField(
model_name='managementcompany',
name='salesforce_id',
field=models.CharField(max_length=30, blank=True),
),
migrations.AddField(
model_name='managementcompany',
name='tax_classification',
field=models.CharField(blank=True, max_length=10,
choices=[(b'I', b'Individual/sole proprietor or single-member LLC'),
(b'C', b'C-Corp'), (b'S', b'S-Corp'), (b'P', b'Partnership'), (b'T',
b'Trust/Estate'), (b'L', b'LLC'), (b'LC', b'LLC (C-Corp)'), (b'LS', b'LLC
(S-Corp)'), (b'LP', b'LLC (Partnership)')]),
),
migrations.AddField(
model_name='managementcompany',
name='tin',
field=models.CharField(max_length=11, blank=True),
),
migrations.AddField(
model_name='managementcompany',
name='vendor_id',
field=models.CharField(max_length=20, null=True, blank=True),
),
migrations.AddField(
model_name='managementcompany',
name='website',
field=models.URLField(null=True, blank=True),
),
# Commenting out the next 5 lines makes the migration work
migrations.AlterField(
model_name='managementcompany',
name='name',
field=models.CharField(max_length=255, db_index=True),
),
migrations.AlterField(
model_name='managementcompany',
name='phone',
field=models.ForeignKey(related_name='+', blank=True,
to='location.Phone', null=True),
),
]
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26054>
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/060.9fe12409dce197519902e1674161f5b9%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.