gpt4 book ai didi

mysql - Laravel 迁移约束语法错误

转载 作者:行者123 更新时间:2023-11-30 21:55:21 25 4
gpt4 key购买 nike

我正在尝试运行 php artisan migrate 命令,但我收到每个约束(如唯一性、索引等)的语法错误。发布的错误来自默认未更改的 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();
});

.环境

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=

感谢您的帮助。

最佳答案

试试这个,因为 unique 不支持 255 个字符的 varchar,你只需声明电子邮件只有 50 个字符

$table->string('email', 50)->unique();

关于mysql - Laravel 迁移约束语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45417362/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com