Support the ongoing development of Laravel.io →
posted 10 years ago
Eloquent
Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

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
(
))

Last updated 2 years ago.
0

Looks like the customer_id you're trying to insert doesn't exist.

Have you tired to create the foreign key wih empty tables ?

Last updated 2 years ago.
0

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);
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

ralanyo ralanyo Joined 6 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.