gpt4 book ai didi

php - laravel 5.4 - php artisan migrate 命令不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 11:38:15 27 4
gpt4 key购买 nike

我有四个迁移文件,当我在命令行中运行 php artisan migrate 时,它显示:

没有要迁移的内容

我还尝试了 php artisan migrate --database=vcp:

数据库 [vcp] 未配置。

我在我的 .env 文件中使用了另一个数据库并再次运行了 php artisan migrate 命令:

Migration table created successfully.
Nothing to migrate.

运行

php artisan migrate:refresh, php artisan migrate:reset, php artisan migrate:status, php artisan migrate -- path="database/migrations/migration_file" 包含这些消息

Nothing to rollback.
Nothing to migrate.
No migrations found

composer dump-autoload or composer update

没有帮助。

这是我的.env 文件

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=vcp
DB_USERNAME=root
DB_PASSWORD=secret

我的 2017_05_10_201750_add_columns_to_users.php

<?php

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

class AddColumnsToUsers extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('status')->default('online');
$table->string('api_token');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('status');
$table->dropColumn('api_token');
});
}
}

请帮忙!

最佳答案

正如您在上面的评论中所述,更改直接在数据库上完成。然后 Nothing to migrate. 是正确的。

尝试理解这个概念,迁移包含文件中的表结构,当您运行迁移时,这些表是在数据库中创建的。当您在迁移文件中进行更改时,您必须再次运行迁移,以便将这些更改反射(reflect)回数据库表。所以流程是:

migration file -> database table

不是

database table -> migration file

关于php - laravel 5.4 - php artisan migrate 命令不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43911087/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com