﻿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
171	Bug, I think, in foreign keys and SQLite	Asheesh Laroia <asheesh@…>	Jacob	"Here's a dump of what should be enough info to reproduce the bug.  I have to foreign keys in the django app I'm trying to build.  Django messes up somewhere and creates two columns with the same name.

I'm assigning to Jason because he recently blogged about adding SQLite support.  If it's mis-assigned, feel free to hand it off to someone else.

{{{
paulproteus@supercore:~/django/kurrency$ echo $DJANGO_SETTINGS_MODULE
kurrency.settings.main
paulproteus@supercore:~/django/kurrency$ echo $PYTHONPATH
/home/paulproteus/django/

paulproteus@supercore:~/django/kurrency/apps/money/models$ cat money.py
from django.core import meta
 
class Person(meta.Model):
    fields = (
        meta.CharField('name', maxlength=200),
    )
 
class Debt(meta.Model):
    fields = (
        meta.ForeignKey(Person, related_name='owed_from'), # the person who owes money
        meta.ForeignKey(Person, related_name='owed_to'), # the person to whom money is owed
        meta.DateTimeField('date', 'date and time the debt was recorded'),
        meta.IntegerField('cents', 'Number of cents for which the debt is'),
        meta.CharField('reason', maxlength=255),
        meta.BooleanField('is_paid')
    )
 
paulproteus@supercore:~/django/kurrency/apps/money/models$ django-admin.py sqlindexes money
CREATE INDEX money_debts_person_id ON money_debts (person_id);
CREATE INDEX money_debts_person_id ON money_debts (person_id);
 
paulproteus@supercore:~/django/kurrency$ django-admin.py init
 
paulproteus@supercore:~/django/kurrency$ django-admin.py install money
Error: money couldn't be installed. Possible reasons:
  * The database isn't running or isn't configured correctly.
  * At least one of the database tables already exists.
  * The SQL was invalid.
Hint: Look at the output of 'django-admin.py sqlall money'. That's the SQL this command wasn't able to run.
The full error: duplicate column name: person_id
 
paulproteus@supercore:~/django/kurrency$ django-admin.py sqlall money
BEGIN;
CREATE TABLE money_persons (
    id integer NOT NULL PRIMARY KEY,
    name varchar(200) NOT NULL
);
CREATE TABLE money_debts (
    id integer NOT NULL PRIMARY KEY,
    person_id integer NOT NULL REFERENCES money_persons (id),
    person_id integer NOT NULL REFERENCES money_persons (id),
    date datetime NOT NULL,
    cents integer NOT NULL,
    reason varchar(255) NOT NULL,
    is_paid bool NOT NULL
);
INSERT INTO packages (label, name) VALUES ('money', 'money');
INSERT INTO content_types (name, package, python_module_name) VALUES ('person', 'money', 'persons');
INSERT INTO content_types (name, package, python_module_name) VALUES ('debt', 'money', 'debts');
COMMIT;
}}}"	defect	closed	Database layer (models, ORM)		normal	invalid			Unreviewed	0	0	0	0	0	0
