【发布时间】:2018-02-02 11:41:58
【问题描述】:
在我开始使用 users 表 ID 作为 blogs 表中的外键并尝试将其迁移到数据库之前,一切正常。我开始收到
SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册以获取正确的语法 ax 在第 1 行使用'unsigned not null,
modelNamevarchar(191) not null,titlevarchar(191) not n' (SQL: create tableblogs(idint unsigned not null auto_increment 主键,user_idvarchar(191) unsigned not null,modelNamevarchar(191) not null,titlevarchar(191) not null,priceint unsigned not null,descriptiontext not n ull,statusint not null,photo_idvarchar(191) not null,company_idvarchar(191) not null default '1',created_attimestamp null,updated_attimestamp null) default c 字符集 utf8mb4 整理 utf8mb4_unicode_ci) 在 Connection.php 第 445 行: SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册以获取正确的语法 ax 在第 1 行的 'unsigned not null,modelNamevarchar(191) not null,titlevarchar(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();
});
}
这是博客表结构
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');
});
}
据我所知,我几乎尝试了所有可能出错的方法,还尝试了在线可用的解决方案,但目前似乎没有任何效果。任何帮助将不胜感激。
【问题讨论】:
标签: php database phpmyadmin migration laravel-5.4