【问题标题】:Why does Laravel Migrations on Windows migrates the first table but not the others?为什么 Windows 上的 Laravel Migrations 会迁移第一个表而不迁移其他表?
【发布时间】:2018-09-06 14:56:24
【问题描述】:

例如,我需要迁移三个迁移表(例如用户、角色、部门)。在 laravel 中,就像发出命令一样简单:

php artisan migrate

但是,我使用的是 Windows(cmd/powershell),每次发出 migrate 命令时,只会迁移第一个表。如果我尝试重新发出 migrate 命令,我会收到一条错误消息,指出“用户表存在”。

我的 laravel 安装有错误还是正常?

为了绕过上面的错误,我必须重命名每个表。例如,如果我迁移了“用户”,那么我需要将用户表重命名为:

"create_users_table_2344747474.sql.bak"

以上对我来说是必要的,以便于其他表的迁移,在本例中为“角色”和“部门”,如上所述。

安装技术规格:

更新:具体错误。说明:如下图所示,“用户表”迁移成功。我可以在mysql中看到它。但是,不会迁移其他表。 Laravel 是 Laravel 框架 5.6.13

更新: 用户表迁移。

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

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

这些其他迁移不会“迁移”到数据库。

【问题讨论】:

  • 我可以知道完整的错误吗?当你输入 php artisan:migrate?在这里打印..
  • 我更新了我的问题并添加了错误图片。正如我的问题中所解释的,发出命令后只迁移一个表:php artisan migrate。
  • 你能发布你的用户迁移吗?
  • 发布您的用户表迁移
  • 我发布了用户迁移表。

标签: php laravel composer-php laravel-5.5 laravel-artisan


【解决方案1】:

你的mysql是什么版本的?根据文档:如果您运行的 MySQL 版本早于 5.7.7 版本或 MariaDB 版本早于 10.2.2 版本,您可能需要手动配置迁移生成的默认字符串长度,以便 MySQL 为他们。您可以通过在 AppServiceProvider 中调用 Schema::defaultStringLength 方法来配置它:

use Illuminate\Support\Facades\Schema;

/**
 * Bootstrap any application services.
 *
 * @return void
 */
public function boot()
{
    Schema::defaultStringLength(191);
}

【讨论】:

  • 我要仔细检查一下。我没有修改数据库版本。我正在使用 MariaDB。
  • 是的。你是对的。我使用了 Xampp[v3.2.2],与 Xampp 捆绑的 MariaDB 发行版是 10.1。我自定义交换了 Xampp[v3.2.2] 附带的 MariaDB[10.1] 与最新版本的 MariaDB:[服务器版本:10.2.14-MariaDB] 的全新安装,现在它可以正常工作了。
【解决方案2】:

我曾经遇到过这样的问题。这是因为用户表中的电子邮件字段,但我通过添加数据的长度来解决它:

public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('email', 255)->unique();
        $table->string('password');
        $table->rememberToken();
        $table->timestamps();
    });
}

然后,执行php artisan migrate:refresh。 如果仍然无法正常工作,请打开您的数据库,然后删除所有表并再次迁移它。希望这可以帮助您解决问题

【讨论】:

  • 你清除了项目中的所有缓存吗? @FullArray
猜你喜欢
  • 2013-08-30
  • 2014-06-21
  • 2015-06-23
  • 2017-05-07
  • 1970-01-01
  • 2021-11-07
  • 2017-02-21
  • 1970-01-01
  • 2017-01-16
相关资源
最近更新 更多