dwijitsolutions / laraadmin

LaraAdmin is a Open source Laravel Admin Panel / CMS which can be used as Admin Backend, Data Management Tool or CRM boilerplate for Laravel with features like Advanced CRUD Generation, Module Manager, Backups and many more.
http://laraadmin.com
MIT License
1.56k stars 538 forks source link

Change of column name when foreign leads to error #282

Closed leopinzon closed 2 years ago

leopinzon commented 6 years ago

Hi guys, thanks a lot for taking the time and effort to develop this awesome boilerplate, it is amazing. Having said that, I wanted to send you an error I found on a project I've working on.

When you already have a CRUD with a foreign key / relationship pointing to another module and you wish to change its column name, a Mysql error comes up for trying to delete the renamed foreign key.

In the following example I did a Car -> Wheels relationship (a column "car" in the wheels table module to select the car it belongs to).

After creating the CRUD and trying to rename the Wheels "car" column name to "car_id", you get the error below:

QueryException in Connection.php line 770:
SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'wheels_car_id_foreign'; check that column/key exists (SQL: alter table `wheels` drop foreign key `wheels_car_id_foreign`)

I'm attaching the entire error log for this error,

foreign_error

It is important to mention: The foreign key wasn't modified but the field itself was, even in the blade templates, controller, etc.

Hope this helps!

Best

theamanchoudhary commented 6 years ago

Refer to https://github.com/dwijitsolutions/laraadmin/issues/277 this solved my problem. Hope it will help :)