With this model inheritance:
{{{
class Account(models.Model):
name = models.CharField (...)
class Source(models.Model):
name = models.CharField(...)
account = models.ForeignKey('Account', related_name='sources')
class SubSource(Source):
uid = models.CharField(...)
class Meta:
unique_together = (
("account", "uid"),
)
}}}
My intended behavior here is to ensure I can only have a single
combination of Accounts and (external) SubSources. I may have multiple
instances of the same external sub-source on the table if used by
different accounts, which is why i'm not simply using `unique` on the
`uid` field.
I can run `django-admin.py check`, which passes, and `django-admin.py
makemigrations`, which passes. But when i try to run `django-admin.py
migrate` it fails with:
{{{
django.db.utils.ProgrammingError: column "account_id" named in key does
not exist
}}}
the generated migration script looks like this:
{{{
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
<snip>
]
operations = [
migrations.AlterUniqueTogether(
name='subsource',
unique_together=set([('account', 'uid')]),
),
]
}}}
I'm sorry that I'm not skilled enough to produce an actual test case.
Thanks.
--
Ticket URL: <https://code.djangoproject.com/ticket/23564>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* needs_better_patch: => 0
* component: Migrations => Database layer (models, ORM)
* needs_tests: => 0
* keywords: => checks
* needs_docs: => 0
* resolution: => duplicate
Comment:
The real issue here is that you shouldn't be allowed to include non-local
fields in `unique_together`. An additional check was added in #22356 which
has been merged into master.
I'm wondering why I didn't backport it to 1.7 right away. Since this can
lead to invalid migrations being created we might want to include it in
1.7.1?
--
Ticket URL: <https://code.djangoproject.com/ticket/23564#comment:1>