1) add new column to table
Link: https://stackoverflow.com/questions/16791613/add-a-new-column-to-existing-table-in-a-migration
To create a migration, you may use the migrate:make command on the Artisan CLI. Use a specific name to avoid clashing with existing models
for Laravel 3:
php artisan migrate:make add_paid_to_users
for Laravel 5+:
php artisan make:migration add_paid_to_users_table --table=users
You then need to use the Schema::table() method (as you’re accessing an existing table, not creating a new one). And you can add a column like this:
public function up()
{
Schema::table('users', function($table) {
$table->integer('paid');
});
}
and don’t forget to add the rollback option:
public function down()
{
Schema::table('users', function($table) {
$table->dropColumn('paid');
});
}
Then you can run your migrations:
php artisan migrate
This is all well covered in the documentation for both Laravel 3:
And for Laravel 4 / Laravel 5:
Edit:
use $table->integer(‘paid’)->after(‘whichever_column’); to add this field after specific column.
2) create table
Tạo table:
php artisan make:migration create_workload_datasources --create=workload_datasources
create model với laravel 7 thì như sau:
php artisan make:model Models/WorkloadDatasource
3) change type column in table
Schema::table('orders', function ($table) {
$table->string('category_id')->change();
});
https://stackoverflow.com/questions/32940495/laravel-migration-table-fields-type-change/40047800
Cuối cùng gõ lệnh php artisan migrate
4) Fix lỗi
SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '0000-00-00 00:00:00' for column `kratos`.`workloads
`.`migrate_end` at row 1 (SQL: alter table `workloads` add `migrate_end` datetime not null)
$table->dateTime('migrate_end')->nullable();