如何更新 Laravel 中 table 内列的数据类型?
How can I update the data type of a column inside a table in Laravel?
我正在尝试更新我的列的数据类型,因为它需要加密。为此我创建了一个新的迁移并尝试了这个:
public function up()
{
Schema::table('users', function(Blueprint $table) {
$table->dropColumn(['team', 'service_number']);
$table->string('team', 188);
$table->string('service_number', 188);
});
}
但是,我得到这个错误:
SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'team' (SQL: alter table `users` add `team` varchar(1024) not null, add `service_number` varchar(1024) not null)
如何更新 table 中列的数据类型?
我认为您需要这样做(尽管不会删除列):
$table->string('team', 188)->change();
$table->string('service_number', 188)->change();
我正在尝试更新我的列的数据类型,因为它需要加密。为此我创建了一个新的迁移并尝试了这个:
public function up()
{
Schema::table('users', function(Blueprint $table) {
$table->dropColumn(['team', 'service_number']);
$table->string('team', 188);
$table->string('service_number', 188);
});
}
但是,我得到这个错误:
SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'team' (SQL: alter table `users` add `team` varchar(1024) not null, add `service_number` varchar(1024) not null)
如何更新 table 中列的数据类型?
我认为您需要这样做(尽管不会删除列):
$table->string('team', 188)->change();
$table->string('service_number', 188)->change();