作者:oooooo1995_395 | 来源:互联网 | 2022-12-29 20:20
如何解决《语法错误或访问冲突:1064:在'unsignednotnull附近使用的语法,modelNamevarchar(191)notnull,titlevarchar(191)notn》经验,为你挑选了1个好方法。
一切都工作正常,直到我开始users
在blogs
表中使用表id作为外键并尝试将其迁移到数据库中.我开始得到错误
SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法中有错误; 检查与您的MariaDB服务器版本对应的手册,以便在第1行使用'unsigned not null,modelName
varchar(191)not null,title
varchar(191)not n' 附近使用正确的SYN ax (SQL:create table blogs
(id
int unsigned not null) auto_increment主键,user_id
varchar(191)unsigned not null,modelName
varchar(191)not null,title
varchar(191)not null,price
int unsigned not null,description
text not n ull,status
int not null,photo_id
varchar(191)not null,company_id
varchar(191 )not null default'1 ',created_at
timestamp null,updated_at
timestamp null)default c haracter set utf8mb4 collate utf8mb4_unicode_ci)在Connection.php第445行:SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法中有错误; 查看与您的MariaDB服务器版本对应的手册,以便在第1行使用'unsigned not null,modelName
varchar(191)not null,title
varchar(191)not n' 附近使用正确的合成器
这是users表结构
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->integer('role_id')->index()->unsigned()->nullable();
$table->integer('is_active')->default(0);
$table->string('name');
$table->string('photo_id')->default('default.png');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
这是博客表结构
public function up()
{
Schema::create('blogs', function (Blueprint $table) {
$table->increments('id');
$table->string('user_id')->unsigned();
$table->string('modelName')->index();
$table->string('title');
$table->integer('price')->unsigned();
$table->text('description')->nullable(false);
$table->integer('status');
$table->string('photo_id');
$table->string('company_id')->default(!null);
$table->timestamps();
// $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('user_id')->refrences('id')->on('users');
});
}
我已经尝试了几乎所有可能出错的知识,并尝试了在线提供的解决方案,但现在似乎没有任何工作.任何帮助将受到高度赞赏.
1> kerbholz..:
$table->string('user_id')->unsigned();
类型的字段string
不能是无符号的.改成
$table->integer('user_id')->unsigned();
这是"引用",而不是"引用".睡一觉;)(也许接受这个答案)