Php 语法错误或访问冲突:1064:使用near';未签名非空,modelName varchar(191)非空,title varchar(191)非n
一切正常,直到我开始在Php 语法错误或访问冲突:1064:使用near';未签名非空,modelName varchar(191)非空,title varchar(191)非n,php,database,phpmyadmin,migration,laravel-5.4,Php,Database,Phpmyadmin,Migration,Laravel 5.4,一切正常,直到我开始在blogs表中使用userstables id作为外键,并尝试将其迁移到数据库中。我开始犯错误了 SQLSTATE[42000]:语法错误或访问冲突:1064您的SQL语法有错误;检查与您的MariaDB服务器版本对应的手册,以获取正确的synt ax在第1行使用接近“unsigned not null,modelNamevarchar(191)not null,titlevarchar(191)not n”(SQL:create tableblogs(idint unsi
blogs
表中使用users
tables id作为外键,并尝试将其迁移到数据库中。我开始犯错误了
SQLSTATE[42000]:语法错误或访问冲突:1064您的SQL语法有错误;检查与您的MariaDB服务器版本对应的手册,以获取正确的synt
ax在第1行使用接近“unsigned not null,modelName
varchar(191)not null,title
varchar(191)not n”(SQL:create tableblogs
(id
int unsigned not null auto\u increment
主键,user\u id
varchar(191)无符号不为空,modelName
varchar(191)无符号不为空,title
varchar(191)无符号不为空,price
int无符号不为空,description
text not n
ull,status
int not null,photo\u id
varchar(191)not null,company\u id
varchar(191)not null默认值'1',created\u at
timestamp null,updated\u at
timestamp null)默认值c
字符集utf8mb4对比utf8mb4\u unicode\u ci)
在Connection.php第445行中:
SQLSTATE[42000]:语法错误或访问冲突:1064您的SQL语法有错误;检查与您的MariaDB服务器版本对应的手册,以获取正确的synt
ax在第1行使用接近“unsigned not null,modelName
varchar(191)not null,title
varchar(191)not n”**
下面是用户表结构
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();
});
}
下面是blogs表结构
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');
});
}
据我所知,我已经尝试了几乎所有可能出现问题的方法,也尝试了在线可用的解决方案,但现在似乎什么都不起作用。任何帮助都将不胜感激。$table->string('user_id')->unsigned()代码>
string
类型的字段不能无符号。改为
$table->integer('user_id')->unsigned()代码>感谢您的更正:)当您连续八个小时编写代码时会发生这种情况:dbutnow我得到SQLSTATE[42000]:语法错误或访问冲突:1064您的SQL语法有错误;检查与您的MariaDB服务器版本相对应的手册,以便在第1行(SQL:alter tableblogs
add constraintblogs\u user\u id\u foreign
foreign key(user\u id
)Connection.php第445行中的引用users
()):SQLSTATE[42000]:语法错误或访问冲突:1064您的SQL语法有错误;检查与您的MariaDB服务器版本相对应的手册,以便在第1行的“')附近使用正确的synt ax,它的参考
,而不是参考
。睡一会儿;)(也许会接受这个答案)事实上,我还有另外两张表,评论和回复分别使用blog_id和comment_id作为外文,我在那里检查拼写,它们是正确的,所以我没有检查f:Dor,因为我一直在复制粘贴。谢谢@kerbholz的帮助和建议:)现在我肯定要休息一下了:D