Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alter table Laravel 5 with migration

Tags:

I'm making a application with laravel 5. I change the field 'vote ' that I have defined as

$ table-> enum ('vote', [ '- 1 ', '0 ', '1 ']);  

and should be as follows

$ table-> enum ('vote', [' 1', ' 2', ' 3', ' 4', ' 5'] ) ; 
like image 692
Sandy Raymond Rodrguez Mendoza Avatar asked Nov 24 '15 17:11

Sandy Raymond Rodrguez Mendoza


People also ask

How do I rename a table in Laravel migration?

To change a table name, you can do this: Schema::rename($currentTableName, $newTableName); You can use the drop or dropIfExists methods to remove an existing table: Schema::drop('users'); Schema::dropIfExists('users');


2 Answers

To do this you should follow these steps:

  1. create a new migration file

    php artisan make:migration update_votes_table 
  2. open the newly created migration file (app_folder\database\migrations{date_migrationfile_was_created}-update_votes_tables.php)

  3. 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

like image 75
davejal Avatar answered Oct 05 '22 22:10

davejal


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 
like image 32
Moode Osman Avatar answered Oct 05 '22 22:10

Moode Osman