On fresh installation of Laravel and Voyager I get the following error:
[Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table `permission_role` add constraint `permission_role_role_id_foreign` foreign ke
y (`role_id`) references `roles` (`id`) on delete cascade)
When I check the created database there is no table roles.
Install Laravel and then Voyager. Once the command php artisan voyager:install is executed, the error shows.
Sounds like the migration didn't finish. Please compare your _migrations table against what's in your database/migrations directory and see if any are missing (there should be a dozen or so)
The migration has really stopped. From all the migrations only 10 are run:
2014_10_12_000000_create_users_table
2014_10_12_100000_create_password_resets_table
2016_01_01_000000_add_voyager_user_fields
2016_01_01_000000_create_data_types_table
2016_01_01_000000_create_pages_table
2016_01_01_000000_create_posts_table
2016_02_15_204651_create_categories_table
2016_05_19_173453_create_menu_table
2016_10_21_190000_create_settings_table
2016_11_30_135954_create_permission_table
What I noticed is missing is a migration in between: 2016_10_21_190000_create_roles_table.php, so the roles table is not created and when the foreign keys for permission_role are created, the migration stops.
Is there something that I am doing wrong and what could be the reason that only this table is not created?
Update:
Renaming the file timestamp from 190000 to 180000 fixed the issue and the migration was executed, but now I get an error on
Seeding data into the database
[Illuminate\Database\QueryException]
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'table_name' cannot be null (SQL: insert into `permissions` (`key`, `table_name`, `updated_at`, `created_at`) values (browse_admin, , 2017-10-16 18:21:33, 2017-10-16 18:21:33))
[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'table_name' cannot be null
[PDOException]
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'table_name' cannot be null
Sounds like something glitched, run artisan migrate:reset and change the migration names back to what they were before and run artisan migrate again. I've had the issue where partial migration runs screws things up before and not just with Voyager.
I don't believe this is related to a glitch. Actually the seed (PermissionsTableSeeder) tries to insert null:
foreach ($keys as $key) {
Permission::firstOrCreate([
'key' => $key,
'table_name' => null,
]);
}
and the Permissions table is defined like this:
Schema::create('permissions', function (Blueprint $table) {
$table->increments('id');
$table->string('key')->index();
$table->string('table_name');
$table->timestamps();
});
so the table does not allow null values for column table_name.
Update:
Making the column nullable() resolves the issue, but I believe that everyone will experience this issue with new installation.
Hmm.... good find @o15a3d4l11s2. I'm thinking that field needs to be nullable. Can you open a PR to add a new migration to add that?
@fletch3555 , I found out that there is a file named 2017_01_15_000000_make_table_name_nullable_in_permissions_table.php in the source code of the project, but this file does not exist when the project is installed in Laravel. Do you have any idea what might be the reason?
Does it exist under vendor/tcg/voyager/? If so, you just need to publish vendor assets (artisan vendor:publish). You may need to --force
Closing due to age. Migrations are no longer published, so this should be fixed anyway.
This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.
Most helpful comment
I don't believe this is related to a glitch. Actually the seed (
PermissionsTableSeeder) tries to insertnull:and the
Permissionstable is defined like this:so the table does not allow null values for column
table_name.Update:
Making the column
nullable()resolves the issue, but I believe that everyone will experience this issue with new installation.