[Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1103 Incorrect table name '' (SQL: alter table `role_user` add constraint `role_user_user_id_foreign` foreign key (`user_id`) references `` (`id`) on delete cascade on update cascade)
Today I pulled a fresh Laravel 5.2 (5.2.31) installation to work on the new project in company, when I was trying to install entrust and execute the migration file I was popped by the above exception error in my Console.
Well was the exception is saying the issue is that there is no column specified for the foreign key on users table of my application.
To fix this you can easily open the entrust migration file and add your users table into it.
The reason that this happens is because when entrust is going to make the migration file it looks into config/auth.php file to lookup the name of your users table.
if you open the auth.php file you can see something similar to below in providers section:
'users' => [ 'driver' => 'eloquent', 'model' => App\User::class, ],
entrust looks for table property within this array to find the name of the users table.
To fix the issue and make entrust migration generation works properly you need to add ‘table’ => ‘users’ in this array.
so the output should look like:
'users' => [ 'driver' => 'eloquent', 'model' => App\User::class, 'table' => 'users' ],
Then you can run php artisan entrust:migration and it will create the migration file with proper value for the foreign key reference.
Incoming search terms:
- laravel error foreign key access violatiln incorrect table name
Thanks for this. But the removal won’t work because it’s not just adding into the js file. On my case it’s replacing all JS files into this single line of code at 431 bytes. So I had to re-upload the sites from backup.
They really should not’ve done that.