Sql 无法将Illumb\Support\Fluent类的对象转换为int
我试图使用Schema::table将列添加到现有表中,但无论我做什么,都会遇到以下错误: “无法将Illumb\Support\Fluent类的对象转换为int” 关键是我不能使用迁移来更新表,因为表是在用户注册时创建的,列是根据它们的选择添加的(15-20个选择) 以下是我用于此目的的代码:Sql 无法将Illumb\Support\Fluent类的对象转换为int,sql,database,laravel,schema,Sql,Database,Laravel,Schema,我试图使用Schema::table将列添加到现有表中,但无论我做什么,都会遇到以下错误: “无法将Illumb\Support\Fluent类的对象转换为int” 关键是我不能使用迁移来更新表,因为表是在用户注册时创建的,列是根据它们的选择添加的(15-20个选择) 以下是我用于此目的的代码: Schema::table($new->id, function ($table2) { - $table2->string('choice_one')->de
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');
});
我试着到处找,但找不到解决办法 尝试传递字符串,而不是像
Schema::table('t_'.$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');
});
通过这种方式,您可以通过
id
传递一个字符串并在将来引用表
,这样就发生了最糟糕的编码器噩梦。我在代码中留下了“-”,所以它试图将它传递到表中。一旦我把它拆下来,一切都正常了。2天的生命过去了表名应该是单一的(如:user_choices),并在该表上创建列user_id,并在此表上存储users表的id。它应该是这样的。表名是单一的,表名是来自用户表的ID,所以它总是唯一的Schema::Table
structure needfirst
param as string,second是Closure。但您在第一个参数中提供了导致错误的integer
。这里的check details尝试了这个,但它显示了相同的错误,并且laravel在下面的行中高亮显示:$table2->string('choice_one')->default('0')代码>有什么想法吗?好的,这里有一些问题,您可以使用Schema::table来更新模式吗?是否返回Schema::table代码块?如果您正在创建模式,为什么不使用schema::create?如果您能展示更多的代码,我们可能会有更好的理解是的,我正在使用Schema::table更新现有的表。我用schema::create在用户第一次注册时创建了表。根据用户选择的设置,我需要更新表以添加具有所选选择的列。这类似于:如果用户选择choice\u one,则更新其表并添加名为choice\u one的列。如果你需要更多的解释,请告诉我