laravel errno 150 foreign key constraint is incorrectly formed

前端 未结 11 1561
陌清茗
陌清茗 2020-12-14 03:09

Can anybody help me to solve this problem?

There are 3 tables with 2 foreign keys:

Schema::create(\'users\', function (Blueprint $table) {
    $table-&         


        
11条回答
  •  半阙折子戏
    2020-12-14 03:49

    we are table villes:

    Schema::create('villes', function (Blueprint $table) {
                $table->bigIncrements('idVille'); // bigIncrement(8 bits)
                $table->string('nomVille');
                $table->timestamps();
            });
    

    foreign key in table users for exemple :

    Schema::table('users', function (Blueprint $table) {
                $table->bigInteger('ville_idVille')->unsigned()->after('tele');
                $table->foreign('ville_idVille')->references('idVille')->on('villes');
            });
    

提交回复
热议问题