【发布时间】:2019-01-28 17:45:10
【问题描述】:
我正在尝试使用 Schema::table 将列添加到现有表中,但无论我做什么都会出现以下错误:
“Illuminate\Support\Fluent 类的对象无法转换为 int”
要点是我不能使用迁移来更新表,因为表是在用户注册时创建的,并且根据他们的选择添加列(15-20 个选择)
这是我为此使用的代码:
Schema::table($new->id, function ($table2) {
-
$table2->string('choice_one')->default('0');
$table2->string('choice_two')->default('0');
$table2->string('choice_three')->default('0');
$table2->string('choice_four')->default('0');
});
我尝试到处搜索,但找不到解决方案。
【问题讨论】:
-
表名应该是单一的(例如:user_choices)并在该表上创建列 user_id 并将用户表的 id 存储在该表上。应该是这样的。
-
表名是单一的,表名是用户表中的ID所以它总是唯一的
-
Schema::table结构需要first参数作为字符串,第二个是闭包。但是您在导致错误的第一个参数中提供了integer。在此处查看详细信息laravel.com/docs/5.6/migrations#columns
标签: sql database laravel schema