On Fri, May 21, 2010 at 2:40 PM, Tim Chase <python.l...@tim.thechases.com>wrote:
> On 05/21/2010 12:31 PM, Victor Subervi wrote: > >> cursor.execute('insert into Baggage values (Null, %s, %s, %s, >> %s)', (flight_id, customer_id, weight, ticket_no)) >> > > You're trying to insert stuff... > > > OperationalError: (1452, 'Cannot add or update a child row: a foreign >> key constraint fails (`seaflight/Baggage`, CONSTRAINT `Baggage_ibfk_2` >> FOREIGN KEY (`customer_id`) REFERENCES `Customers` (`id`))') >> > > But the value you're giving for the customer_id doesn't exist in the > Customers table (as mandated by the FK). Or perhaps the column-order for > Baggage isn't what you think it is. I always specify it explicitly: > > INSERT INTO Baggage ( > something, flight_id, customer_id, weight, ticket_no > ) VALUES (Null, %s, %s, %s, %s) > > just in case the table column-order ever changes during a database update. > As it turns out, my error was confusing my tables Customers and Passengers. I was calling customer_id when I should have been calling passenger_id, which is why MySQL couldn't find the correct values <:-} beno > >
-- http://mail.python.org/mailman/listinfo/python-list