Error applying evolution: column "accountingdocument_ptr" referenced in foreign key constraint does not exist

58 views
Skip to first unread message

Jan Ostrochovsky

unread,
Sep 7, 2009, 4:27:17 AM9/7/09
to Django Evolution
Hello,

Django Evolution is great help, until today, I stick in the trouble:

class AccountingDocument(models.Model):
...

class Invoice(AccountingDocument):
...

class InvoiceItem(models.Model):
...
invoice = models.ForeignKey('Invoice')

(I am using multi-table inheritance, if more lines useful, I'll paste
them also.)

The result of evolution is:

ostry@mirka-markiza:~/Dropbox/My Documents/Business/DSBIS$ python
manage.py evolve --hint --sql
-- Evolve application core
ALTER TABLE "core_invoiceitem" ADD COLUMN "invoice_id" integer NOT
NULL REFERENCES "core_invoice" ("accountingdocument_ptr") DEFERRABLE
INITIALLY DEFERRED;
CREATE INDEX "core_invoiceitem_invoice_id" ON
"core_invoiceitem" ("invoice_id");
ostry@mirka-markiza:~/Dropbox/My Documents/Business/DSBIS$ python
manage.py evolve --hint --execute
You have requested a database evolution. This will alter tables
and data currently in the 'dsbis_db' database, and may result in
IRREVERSABLE DATA LOSS. Evolutions should be *thoroughly* reviewed
prior to execution.
Are you sure you want to execute the evolutions?
Type 'yes' to continue, or 'no' to cancel: yes
Error applying evolution: column "accountingdocument_ptr" referenced
in foreign key constraint does not exist

The cause is, that there is no such attribute: accountingdocument_ptr,
but here is accountingdocument_ptr_id.

I am using Django 1.1 under Linux Ubuntu 9.04.

Probably possible workaround: modify SQL - add "_id" at the end of
"accountingdocument_ptr", and run the statement from PostgreSQL
console, not from Django Evolution.

It seems, that it has run successfully:
ALTER TABLE "core_invoiceitem" ADD COLUMN "invoice_id" integer NOT
NULL REFERENCES "core_invoice" ("accountingdocument_ptr_id")
DEFERRABLE INITIALLY DEFERRED;
CREATE INDEX "core_invoiceitem_invoice_id" ON
"core_invoiceitem" ("invoice_id");

Does anybody see better solution?
Thanks in advance.

Ostry
Reply all
Reply to author
Forward
0 new messages