2016-05-16 103 views
1

我的代码是在这里,当我尝试使用laravel

public function up() 
    { 
     Schema::create('semesters', function (Blueprint $table) { 
//   $table->increments('id'); 
      $table->engine = 'InnoDB'; 

      $table->string('semester_id')->unique()->unsigned(); 

      $table->timestamps(); 

     }); 
    } 

错误添加主键的数据类型为字符串错误发生在这里

[照亮\数据库\ QueryException] SQLSTATE [ 42000]:语法错误 或访问冲突:1064您的SQL语法中有错误;检查 对应于您MariaDB的服务器版本的 正确的语法使用手动接近“无符号不为空,created_at倍夯实 默认0不为空,updated_at时报”在1号线(SQL:CREATE TABLE semesterssemester_id文本签名不为空,created_at 时间戳默认0不为空,updated_at时间戳默认0不 空)默认字符S等UTF8整理utf8_unicode_ci发动机= InnoDB的)

+1

你不混合型? 'string' VS'unsigned'? ();}无符号();' 到 – Alex

+0

我想要字符串数据类型到我的主键 –

+1

所以删除' - >无符号();'部分然后 – Alex

回答

2

您混合类型:stringunsigned(这是INT

所以如果你需要此列是你应该得到这里摆脱unsigned part的字符串:

$table->string('semester_id')->unique()->unsigned(); <--- 

让行变成了:

$table->string('semester_id')->unique();