douchao1864 2017-10-11 05:21
浏览 39
已采纳

迁移laravel 5.5:无法创建除users表和password_reset表之外的表

i have 9 tables, when i run command :

php artisan migrate

only users table, migration table and password_reset table are created in my database. this is my sample code


use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateAlatsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('alats', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('merk_id')->unsigned();
            $table->integer('kategori_id')->unsigned();
            $table->integer('operator_id')->unsigned();
            $table->string('nama');
            $table->string('no_plat',15);
            $table->date('tahun');
            $table->string('volume',20);
            $table->text('keterangan');
            $table->enum('status',['ada','disewa','servis']);
            // $table->timestamp('created_at');
            // $table->timestamp('updated_at');
            $table->timestamps();
            $table->foreign('merk_id')->references('id')->on('merks')->onDelete('CASCADE');
            $table->foreign('kategori_id')->references('id')->on('kategoris')->onDelete('CASCADE');
            $table->foreign('operator_id')->references('id')->on('operators')->onDelete('CASCADE');
        });
    }

    public function down()
    {
        Schema::dropIfExists('alats');
    }
}

please help me..?

  • 写回答

4条回答 默认 最新

  • duangang2825 2017-10-11 05:31
    关注

    The migration files need to be migrated in right order. You can't migrate a table with a non existing foreign key.

    You probably have a foreign key in some migration and the id key for that will come to existence later in the next migration file. That is why you get this error.

    Check your migration files and watch out on order they get created.

    For example if you have a foreign key alats_merk_id_foreign then the migration file with alats_merk_id must be migrated before. Hope that this will help you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥100 数字取证课程 关于FAT文件系统的操作
  • ¥15 如何使用js实现打印时每页设置统一的标题
  • ¥15 安装TIA PortalV15.1报错
  • ¥15 能把水桶搬到饮水机的机械设计
  • ¥15 Android Studio中如何把H5逻辑放在Assets 文件夹中以实现将h5代码打包为apk
  • ¥15 使用小程序wx.createWebAudioContext()开发节拍器
  • ¥15 关于#爬虫#的问题:请问HMDB代谢物爬虫的那个工具可以提供一下吗
  • ¥15 vue3+electron打包获取本地视频属性,文件夹里面有ffprobe.exe 文件还会报错这是什么原因呢?
  • ¥20 用51单片机控制急停。
  • ¥15 孟德尔随机化结果不一致