JosephSilber / bouncer

Laravel Eloquent roles and abilities.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

error foreign keys with Planetscale

0528Makoto opened this issue · comments

I am using planetscale for the database

When executing the command
vapor deploy with the 'php artisan migrate --force' hook shows me the following message

{
    "message": "SQLSTATE[HY000]: General error: 1105 VT10001: foreign key constraints are not allowed (Connection: mysql, SQL: alter table `assigned_roles` add constraint `assigned_roles_role_id_foreign` foreign key (`role_id`) references `roles` (`id`) on delete cascade on update cascade)",
    "context": {
        "exception": {
            "class": "Illuminate\\Database\\QueryException",
            "message": "SQLSTATE[HY000]: General error: 1105 VT10001: foreign key constraints are not allowed (Connection: mysql, SQL: alter table `assigned_roles` add constraint `assigned_roles_role_id_foreign` foreign key (`role_id`) references `roles` (`id`) on delete cascade on update cascade)",
            "code": 0,
            "file": "\/var\/task\/vendor\/laravel\/framework\/src\/Illuminate\/Database\/Connection.php:795",
            "previous": {
                "class": "PDOException",
                "message": "SQLSTATE[HY000]: General error: 1105 VT10001: foreign key constraints are not allowed",
                "code": 0,
                "file": "\/var\/task\/vendor\/laravel\/framework\/src\/Illuminate\/Database\/Connection.php:580"
            }
        },
        "aws_request_id": "8f016363-be03-41c0-a5a4-acbfa09fbb2c"
    },
    "level": 400,
    "level_name": "ERROR",
    "channel": "staging",
    "datetime": "2023-08-09T17:23:20.228943-05:00",
    "extra": []
}

my temporary solution was to comment the lines

            $table->foreign('ability_id')
                  ->references('id')->on(Models::table('abilities'))
                  ->onUpdate('cascade')->onDelete('cascade');

would this be the correct solution?

Correct.

If your database doesn't support foreign key constraints, then they should be removed from your migration file.

thx, but would this affect the operation in any way? I understand that it is only a relation at the database level

It shouldn't be a problem.