Hi all

The following (simplified) model gives the SQL error "ERROR:  column
"invoice_number" does not exist":

class Invoice(meta.Model):
    invoice_number = meta.PositiveIntegerField(primary_key=True)

class Invoice_item(meta.Model): # General invoice item
    invoice_number = meta.ForeignKey(Invoice)
    id = meta.AutoField('ID', primary_key=True)

This is to expected because the generated SQL for Invoice_item looks like this:

CREATE TABLE "invoicing_invoice_items" (
    "invoice_number_id" integer CHECK ("invoice_number" >= 0) NOT NULL
REFERENCES "invoicing_invoices" ("invoice_number"),
    "id" serial NOT NULL PRIMARY KEY
);

Where does this superfluous _id come from? It's not in the model. And
if it's automagically added, why isn't it added to the CHECK clause?
What's that CHECK clause doing there anyway, it's already in the
referenced table?

Thanks for any help, Arthur.

Reply via email to