In some versions of Laravel you need to specify the $table->increments('id')
as $table->increments('id')->unsigned()
to match the standard integer field $table->integer('customer_id')
because the increments was saved as INT(11) and the standard integer as INT(10).
I didn't had this problem with Laravel4.1
Thanks i changed that and now i get this error. Andy ideas?
[Exception]
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (bbgapp
.<result 2 when explaining filename '
#sql-2d1_381034'>, CONSTRAINT customers_memberships_customers_id_foreign
FOREIGN KEY (customers_id
) REFERENCES customers
(id
)) (SQL: alter table customers_m emberships
add constraint customers_memberships_customers_id_foreign foreign key (customers_id
) references customers
(id
) on delete restrict) (Bindings: array
(
))
Looks like the customer_id
you're trying to insert doesn't exist.
Have you tired to create the foreign key wih empty tables ?
Okay i think i figure it out using this query on the database. Looks like there was a customers_id from a customer that didn't' exist anymore in the customers_memberships table. It was causing the constraint error.
select * from customers_memberships where customers_id not in (select id from customers);
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community