I’m trying to make a relational database that connects 3 different tables. The main program database contains the vendors, that links to invoices from each vendor, then the invoices links to items purchased in that invoice.
tempcur.execute("""CREATE TABLE program (
vendorid INTEGER PRIMARY KEY,
vendor TEXT,
phone TEXT,
store INTEGER)""")
tempcur.execute("""CREATE TABLE dairystore (
invoice INTEGER REFERENCES program(vendorid),
date VARCHAR)""")
tempcur.execute("""CREATE TABLE invoices(
item INTEGER REFERENCES dairystore(invoice),
shipped VARCHAR,
description TEXT,
weight INTEGER,
price INTEGER,
amount INTEGER)""")
No, you have a mistake in
dairystoretable. It should be the following:You’re trying to reference to
dairystore.invoicefrominvoicestable, sodairystore.invoicemust be the id of record. In your codedairystore.invoicecan’t be the id of record because it is reference toprogram.vendoridand its values will be equal to ids of records inprogramtable.