通过迁移改变 table Laravel 5
Alter table Laravel 5 with migration
我正在 laravel 5 申请。
我将字段 'vote ' 更改为
$ table-> enum ('vote', [ '- 1 ', '0 ', '1 ']);
应该如下
$ table-> enum ('vote', [' 1', ' 2', ' 3', ' 4', ' 5'] ) ;
要做到这一点,您应该遵循以下步骤:
创建一个新的迁移文件
php artisan make:migration update_votes_table
打开新建的迁移文件(app_folder\database\migrations{date_migrationfile_was_created}-update_votes_tables.php)
更改您要更改的列
有关详细信息,请参阅 documentation on database migrations
注意:如果您将迁移文件添加到问题中,我们可以提供更详细的帮助
这是我的做法:
php artisan make:migration Alter_votes_to_tableName --table=tableName
打开文件然后修改
php artisan migrate
首先使用以下命令创建新迁移
php artisan make:migration Alter_your_comment_yourTableName --table=yourTableName
根据您的要求更改文件,然后运行composer
中的以下命令
php artisan migrate
修改列需要 doctrine/dbal
包。
安装包
composer require doctrine/dbal
创建迁移
php artisan make:migration add_values_to_vote_column_in_votes_table
更新迁移文件
Schema::table('votes', function (Blueprint $table) {
$table->enum('vote', [' 1', ' 2', ' 3', ' 4', ' 5'])->change();
});
运行迁移
php artisan migrate
我正在 laravel 5 申请。 我将字段 'vote ' 更改为
$ table-> enum ('vote', [ '- 1 ', '0 ', '1 ']);
应该如下
$ table-> enum ('vote', [' 1', ' 2', ' 3', ' 4', ' 5'] ) ;
要做到这一点,您应该遵循以下步骤:
创建一个新的迁移文件
php artisan make:migration update_votes_table
打开新建的迁移文件(app_folder\database\migrations{date_migrationfile_was_created}-update_votes_tables.php)
更改您要更改的列
有关详细信息,请参阅 documentation on database migrations
注意:如果您将迁移文件添加到问题中,我们可以提供更详细的帮助
这是我的做法:
php artisan make:migration Alter_votes_to_tableName --table=tableName
打开文件然后修改
php artisan migrate
首先使用以下命令创建新迁移
php artisan make:migration Alter_your_comment_yourTableName --table=yourTableName
根据您的要求更改文件,然后运行composer
中的以下命令php artisan migrate
修改列需要 doctrine/dbal
包。
安装包
composer require doctrine/dbal
创建迁移
php artisan make:migration add_values_to_vote_column_in_votes_table
更新迁移文件
Schema::table('votes', function (Blueprint $table) { $table->enum('vote', [' 1', ' 2', ' 3', ' 4', ' 5'])->change(); });
运行迁移
php artisan migrate