﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
23564	Django migration fails on unqiue_together with model subclass references	David Binetti	nobody	"I've searched around and can't find a bug for this behavior, so here goes...

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.  

"	Bug	closed	Database layer (models, ORM)	1.7	Normal	duplicate	checks		Unreviewed	0	0	0	0	0	0
