小编fra*_*vel的帖子

Laravel Migration外键约束不正确

迁移我的数据库时出现此错误,下面是我的代码,后面是我在尝试运行迁移时遇到的错误.

 public function up()
    {
        Schema::create('meals', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id')->unsigned();
            $table->integer('category_id')->unsigned();
            $table->string('title');
            $table->string('body');
            $table->string('meal_av');
            $table->timestamps();

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

            $table->foreign('category_id')
                ->references('id')
                ->on('categories')
                ->onDelete('cascade');
        });
    }  
Run Code Online (Sandbox Code Playgroud)

错误信息

[Illuminate\Database\QueryException]                                         
      SQLSTATE[HY000]: General error: 1005 Can't create table `meal`.`#sql-11d2_1  
      4` (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter   
      table `meals` add constraint meals_category_id_foreign foreign key (`catego  
      ry_id`) references `categories` (`id`) on delete cascade) 
Run Code Online (Sandbox Code Playgroud)

mariadb laravel-5 laravel-6

26
推荐指数
12
解决办法
4万
查看次数

如何在 Laravel 中显示 phpinfo() 以调试 PHP?

显示 PHP 配置的最简单方法是什么

phpinfo();
Run Code Online (Sandbox Code Playgroud)

在 Laravel 应用程序中,在开发环境中调试本地 PHP 配置?

背景:

我需要在我的Mac上找出brew将php.ini读取的文件放置在哪里。

php laravel

7
推荐指数
2
解决办法
2万
查看次数

标签 统计

laravel ×1

laravel-5 ×1

laravel-6 ×1

mariadb ×1

php ×1