doulun1939 2019-05-28 19:46
浏览 122

如何修复Laravel 5.3中的字段创建错误?

I have a migration that correctly created table at local vagrant server, but when I tried migrate at VPS with nginx it encounters strange error.

Local env is Vagrant/homestead (I don't know OS, sorry), VPS env is Debian 8, nginx. Laravel version 5.3 Migrations have to create 12 tables, but problem encountered before the end process, so 10 tables only created. By the way it shows that env and other settings is OK (I think) and just in 1 table 1 field is error

this is creation code:

public function up()
    {
        Schema::create('vicards', function (Blueprint $table) {
            $table->increments('id');
            $table->string('visi_slug', 100);
            $table->unique('visi_slug', 'visi_slug_unique');
            $table->integer('user_id');
            $table->index('user_id', 'cards_user_id_index');
            $table->string('user_slug', 100);
            $table->index('user_slug', 'cards_user_slug_index');
            $table->string('avatar', 44)->default(0);
            $table->string('header', 80);
            $table->string('price', 12);
            $table->text('description');
            $table->text('pictures'); // 5 pics * 20 symbols + 4 commas
            $table->text('videos'); // 3 videos * 41 symbols + 2 commas
            $table->text('contacts'); //
            $table->text('links'); // links separated by commas
            $table->text('styles'); // object serialized
            $table->tinyInteger('actual', 1)->default(0);
            $table->timestamps();
        });
    }

problem invokes this field

$table->tinyInteger('actual', 1)->default(0);

artisan interprets it in:

 `actual` tinyint not null default '0' auto_increment primary key

and off-course it is error because 'auto_increment primary key' already exist - 1st field

Expected result - regular table creation.

I got error:

" [Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'actual' (SQL: create table vicards (id int unsigned not null auto_increment primary key, visi_slug varchar(100) not null, user_id int not null, user_slug varchar(100) not null, avatar varchar (44) not null default '0', header varchar(80) not null, price varchar(12) not null, description text not null, pictures text not null, videos text not null, contacts text not null, links text not null, styles text not null, actual tinyint not null default '0' auto_inc rement primary key, created_at timestamp null, updated_at timestamp null) default character set utf8 collate utf8_unicode_ci)"

What is cause of this error? Help me please.

  • 写回答

1条回答 默认 最新

  • dongle7637 2019-05-28 20:45
    关注

    Do not use lenght value, just create tinyint with default value:

    $table->tinyInteger('actual')->default(0);
    
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?