我正在尝试运行php artisan migrate命令,但是我遇到了像unique,index等所有限制的语法错误。发布的错误来自默认的未更改的create_users_table迁移,因为它是第一次迁移到进程。当我从电子邮件列中删除此唯一约束时,我在下次迁移中获得了另一个约束的相同错误。我认为错误信息中显示的“设备唯一”可能存在错误。它应该是'添加独特'。
错误
[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in
your SQL syntax; check the manual that corresponds to your MySQL server version for
the right syntax to use near 'devices unique `users_email_unique`(`email`)'
at line 1 (SQL: alter table `users` devices unique `users_email_unique`(`email`))
[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in
your SQL syntax; check the manual that corresponds to your MySQL server
version for the right syntax to use near 'devices unique
`users_email_unique`(`email`)' at line 1
移植
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
.ENV
APP_NAME=Project
APP_ENV=local
APP_KEY=base64:jRIQ9RxhMYRK9UJXgme1KlA6bd1rA0OGyK96SdBP1nI=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://project.dev
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=project
DB_USERNAME=homestead
DB_PASSWORD=secret
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
感谢您的帮助。
答案 0 :(得分:0)
试试这个,因为255字符varchar的唯一不支持,你只需要声明电子邮件只有50个字符
$ table-> string('email',50) - > unique();