JosephSilber / bouncer

Laravel Eloquent roles and abilities.
MIT License
3.43k stars 330 forks source link

error foreign keys with Planetscale #635

Closed 0528Makoto closed 11 months ago

0528Makoto commented 1 year ago

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?

JosephSilber commented 1 year ago

Correct.

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

0528Makoto commented 1 year ago

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

JosephSilber commented 1 year ago

It shouldn't be a problem.