无法将Illuminate \ Support \ Fluent类的对象转换为int

时间:2018-08-22 12:49:12

标签: sql database laravel schema

我正在尝试使用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');
        });

我尝试到处搜索,但是找不到解决方案。

2 个答案:

答案 0 :(得分: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');
        });

这样,您可以传递字符串,并在以后通过table引用id

答案 1 :(得分:0)

好的,所以最糟糕的编码器噩梦发生了。我在代码中留下了“-”,因此它试图将其传递给表。删除后一切正常。 2天的生命消失了