简体   繁体   English

: 1005 无法创建表 `shop`.`role_user` (errno: 150 “外键约束格式不正确”)")

[英]: 1005 Can't create table `shop`.`role_user` (errno: 150 “Foreign key constraint is incorrectly formed”)")

Hey guys I tried too much stuff and read some blogs or discussion I didn't fix my problem I'm new in laravel this project.嘿伙计们,我尝试了太多东西并阅读了一些博客或讨论我没有解决我的问题我是 laravel 这个项目的新手。 I got error when I want to create to database this error like当我想创建数据库时出现错误,例如

E:\xampp\htdocs\shop\vendor\laravel\framework\src\Illuminate\Database\Connection.php:463
      PDOException::("SQLSTATE[HY000]: General error: 1005 Can't create table `shop`.`role_user` (errno: 150 "Foreign key constraint is incorrectly formed")")

  2   E:\xampp\htdocs\shop\vendor\laravel\framework\src\Illuminate\Database\Connection.php:463
      PDOStatement::execute()

class CreateRoleAndPermissionTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('roles', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('title')->nullable();
            $table->timestamps();
        });
        Schema::create('permissions', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('title')->nullable();
            $table->timestamps();
        });

        Schema::create('role_user', function (Blueprint $table) {
            $table->integer('role_id')->unsigned();
            $table->integer('user_id')->unsigned();

            $table->foreign('role_id')
                ->references('id')
                ->on('roles')
                ->onDelete('cascade')
                ->onUpdate('cascade');

            $table->foreign('user_id')
                ->references('id')
                ->on('users')
                ->onDelete('cascade')
                ->onUpdate('cascade');

            $table->primary(['role_id','user_id']);
        });

        Schema::create('permission_role', function (Blueprint $table) {
            $table->integer('role_id')->unsigned();
            $table->integer('permission_id')->unsigned();


            $table->foreign('role_id')
                ->references('id')
                ->on('roles')
                ->onDelete('cascade')
                ->onUpdate('cascade');

            $table->foreign('permission_id')
                ->references('id')
                ->on('permissions')
                ->onDelete('cascade')
                ->onUpdate('cascade');
            $table->primary(['permission_id','role_id']);
        });


    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('role_and_permission');
    }

Change all instances of integer to biginteger , I am assuming you are using a current version of Laravel which changed the increment field to 'biginteger'.biginteger integer我假设您使用的是 Laravel 的当前版本,它将增量字段更改为“biginteger”。 And $table->increments('id');$table->increments('id'); to $table->id();$table->id();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何在 Laravel 中修复此错误”1005 无法创建表 `englishcollage`.`role_user`(错误号:150“外键约束的格式不正确” - how can i fix this eror in laravel" 1005 Can't create table `englishcollage`.`role_user` (errno: 150 "Foreign key constraint is incorrectly formed" 一般错误:1005 无法创建表(错误号:150“外键约束格式不正确”) - General error: 1005 Can't create table (errno: 150 "Foreign key constraint is incorrectly formed") 常规错误:1005无法创建表errno:150“外键约束格式错误”) - General error: 1005 Can't create table errno: 150 “Foreign key constraint is incorrectly formed”) 一般错误:1005 无法创建表...(errno:150“外键约束格式不正确” - General error : 1005 Can't create table ... (errno:150 "Foreign key constraint is incorrectly formed" SQLSTATE[HY000]: 一般错误: 1005 Can't create table `school`.`posts` (errno: 150 "Foreign key constraint is wrongly forms") - SQLSTATE[HY000]: General error: 1005 Can't create table `school`.`posts` (errno: 150 "Foreign key constraint is incorrectly formed") Laravel 一般错误:1005 无法创建表`categories_products`(错误号:150“外键约束的格式不正确”) - Laravel General error: 1005 Can't create table `categories_products` (errno: 150 "Foreign key constraint is incorrectly formed") 无法创建表`clothing`.`clothes`(错误号:150“外键约束形成不正确”)”)Laravel 7 - Can't create table `clothing`.`clothes` (errno: 150 "Foreign key constraint is incorrectly formed")") Laravel 7 SQLSTATE[HY000]: General error: 1005 Can't create table `business`.`users` (errno: 150 "Foreign key constraint is incorrectly formed") Laravel 7 - SQLSTATE[HY000]: General error: 1005 Can't create table `business`.`users` (errno: 150 "Foreign key constraint is incorrectly formed") Laravel 7 (错误号:150“外键约束格式不正确”) - (errno: 150 “Foreign key constraint is incorrectly formed”) errno:150外键约束格式错误 - errno: 150 Foreign key constraint is incorrectly formed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM