在alter table语法错误或访问冲突时:1064你的sql语法有错误;

时间:2017-06-24 06:09:30

标签: laravel laravel-5.4

当我正在迁移时,我得到了这个error 另外还有两个用于用户的迁移文件,一个用于创建,另一个用于修改alter table下面的代码id。因此,我无法进一步迁移表格,如果可能的话,请提供任何关于tuts的链接。迁移

这是我的迁移代码,它可以改变表格

    public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->integer('active')->after('id')->unsigned()->nullable();
            $table->integer('status')->after('active')->unsigned()->nullable();
            $table->string('sysid')->after('status')->nullable();
            $table->string('workarea', 200)->after('sysid')->nullable();
            $table->string('first', 50)->after('name');
            $table->string('last', 50)->after('first');
            $table->text('bio')->nullable()->after('last');
            $table->string('cover_image', 50)->nullable()->after('bio');
            $table->json('score')->nullable()->after('cover_image');
            $table->integer('language_id')->nullable()->unsigned();
            $table->integer('company_id')->nullable()->unsigned();
            $table->integer('team_id')->nullable()->unsigned();
//            $table->json('avatar')->nullable();
            $table->text('avatar')->nullable();
            $table->foreign('language_id')->references('id')->on('languages');
            $table->foreign('company_id')->references('id')->on('companies');
            $table->foreign('team_id')->references('id')->on('teams');

        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('users', function (Blueprint $table) {

            $table->dropForeign('users_language_id_foreign');
            $table->dropForeign('users_company_id_foreign');
            $table->dropForeign('users_team_id_foreign');

            $table->dropColumn('active');
            $table->dropColumn('status');
            $table->dropColumn('language_id');
            $table->dropColumn('company_id');
            $table->dropColumn('team_id');
            $table->dropColumn('first');
            $table->dropColumn('last');
            $table->dropColumn('bio');
            $table->dropColumn('cover_image');
            $table->dropColumn('score');

        });

    }

错误接近cover_image不知道我做错了什么 提前谢谢

1 个答案:

答案 0 :(得分:0)

你的错误就在这一行

 $table->json('score')->nullable()->after('cover_image');

更改您的数据类型如果您想将其作为整数

,它将正常工作
  public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->integer('active')->after('id')->unsigned()->nullable();
            $table->integer('status')->after('active')->unsigned()->nullable();
            $table->string('sysid')->after('status')->nullable();
            $table->string('workarea', 200)->after('sysid')->nullable();
            $table->string('first', 50)->after('name');
            $table->string('last', 50)->after('first');
            $table->text('bio')->nullable()->after('last');
            $table->string('cover_image', 50)->nullable()->after('bio');
            $table->integer('score')->nullable()->after('cover_image');
            $table->integer('language_id')->nullable()->unsigned();
            $table->integer('company_id')->nullable()->unsigned();
            $table->integer('team_id')->nullable()->unsigned();
//            $table->json('avatar')->nullable();
            $table->text('avatar')->nullable();
            $table->foreign('language_id')->references('id')->on('languages');
            $table->foreign('company_id')->references('id')->on('companies');
            $table->foreign('team_id')->references('id')->on('teams');

        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('users', function (Blueprint $table) {

            $table->dropForeign('users_language_id_foreign');
            $table->dropForeign('users_company_id_foreign');
            $table->dropForeign('users_team_id_foreign');

            $table->dropColumn('active');
            $table->dropColumn('status');
            $table->dropColumn('language_id');
            $table->dropColumn('company_id');
            $table->dropColumn('team_id');
            $table->dropColumn('first');
            $table->dropColumn('last');
            $table->dropColumn('bio');
            $table->dropColumn('cover_image');
            $table->dropColumn('score');

        });

    }

认为它适合你