[英]Alter table Laravel 5 with migration
I'm making a application with laravel 5. I change the field 'vote ' that I have defined as我正在使用 laravel 5 制作应用程序。我更改了我定义为的字段“投票”
$ table-> enum ('vote', [ '- 1 ', '0 ', '1 ']);
and should be as follows并且应该如下
$ table-> enum ('vote', [' 1', ' 2', ' 3', ' 4', ' 5'] ) ;
To do this you should follow these steps:为此,您应该按照以下步骤操作:
create a new migration file创建一个新的迁移文件
php artisan make:migration update_votes_table
open the newly created migration file (app_folder\\database\\migrations{date_migrationfile_was_created}-update_votes_tables.php)打开新创建的迁移文件(app_folder\\database\\migrations{date_migrationfile_was_created}-update_votes_tables.php)
change the columns you want to change更改要更改的列
For more details see the documentation on database migrations有关更多详细信息,请参阅有关数据库迁移的文档
Note: If you add your migrations file to the question we could provide more detailed help注意:如果您将迁移文件添加到问题中,我们可以提供更详细的帮助
this how i do it:这就是我的做法:
php artisan make:migration Alter_votes_to_tableName --table=tableName
open the file and change it then打开文件并更改它然后
php artisan migrate
first of all create new migration using below command首先使用以下命令创建新的迁移
php artisan make:migration Alter_your_comment_yourTableName --table=yourTableName
change the file as per your requirements and after that run the below command in composer根据您的要求更改文件,然后在 Composer 中运行以下命令
php artisan migrate
Modifying Columns would require doctrine/dbal
package.修改列需要
doctrine/dbal
包。
Install the Package安装包
composer require doctrine/dbal
Create a migration创建迁移
php artisan make:migration add_values_to_vote_column_in_votes_table
Update the migration file更新迁移文件
Schema::table('votes', function (Blueprint $table) { $table->enum('vote', [' 1', ' 2', ' 3', ' 4', ' 5'])->change(); });
Run the migration运行迁移
php artisan migrate
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.