【问题标题】:nothing to migrate laravel 4.2没有什么可以迁移 laravel 4.2
【发布时间】:2016-07-11 12:10:03
【问题描述】:

为什么不能,而且似乎没什么可迁移的?

迁移的时候创建表authors和books都可以,但是外键之后就不行了

迁移添加外来:

public function up()
    {
        Schema::table('books', function(Blueprint $table) {
            $table->foreign('author_id')->references('id')->on('authors')
                ->onDelete('restrict')
                ->onUpdate('cascade');
        });
    }

使用这个:

php artisan migrate 

还有这个:

php artisan migrate --path=app/database/migrations/2016_07_11_105204_add_foreign_key_to_books.php

还是不行,

桌书:

public function up()
{
    Schema::create('books', function(Blueprint $table) {
        $table->increments('id');
        $table->string('title');
        $table->integer('author_id')->unsigned();
        $table->integer('amount')->unsigned();
        $table->timestamps();
    });
}

表作者:

public function up()
    {
        Schema::create('authors', function(Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->timestamps();
        });
    }

感谢您的帮助..

【问题讨论】:

  • 如果您手动添加了迁移,请尝试composer dumpautoload 以使其被识别。

标签: php laravel migrate


【解决方案1】:

我也有类似的问题。我想办法。这不是官方的

  1. 首先进入数据库。如果你使用 mysql。有迁移表。看到迁移表有ROW 就像您的迁移文件名一样,例如 2016_07_11_105204_books。
  2. 通过删除命令删除行。
  3. 删除或删除 books 表。
  4. 然后转到命令提示符。再次提供命令php artisan migrate

它对我有用。

【讨论】:

    【解决方案2】:

    Laravel 4.2 的 schema 不支持更新列。所以你可以这样做(先删除它,然后将它创建为外键):

    Schema::table('books', function(Blueprint $table) {
    {
        $table->dropColumn('author_id');
        $table->integer('author_id')->after('title')->unsigned();
        $table->foreign('author_id')->references('id')->on('authors')
                ->onDelete('restrict')
                ->onUpdate('cascade');
    }
    

    【讨论】:

      【解决方案3】:

      对于带有 --path 选项的启动迁移调用命令,它只有目录路径。

      php artisan migrate --path=app/database/migrations
      

      你用文件名设置-path

      【讨论】:

        猜你喜欢
        • 2019-06-03
        • 2017-01-22
        • 1970-01-01
        • 2017-05-05
        • 1970-01-01
        • 2015-04-07
        • 2016-02-04
        • 2014-04-27
        相关资源
        最近更新 更多