我尝试使用新的laravel项目,我在php artisan migrate
In Connection.php line 664:
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 th
e right syntax to use near ') default character set utf8mb4 collate utf8mb4_unicode_ci' at line 1 (SQL: create table `addresses` () default character set utf8mb4 c
ollate utf8mb4_unicode_ci)
In Connection.php line 452:
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 th
e right syntax to use near ') default character set utf8mb4 collate utf8mb4_unicode_ci' at line 1
到目前为止我做了什么:
我在下面添加了代码AppServiceProvider
use Illuminate\Support\Facades\Schema;
/////
public function boot()
{
Schema::defaultStringLength(191);
}
并更改了database.php
'strict' => true,
要
'strict' => false,
仍然会得到同样的错误。
正如我的错误代码中提到的,这与我的addresses
表有关。这是:
public function up()
{
Schema::create('addresses', function (Blueprint $table) {
$table->increments('id');
$table->string('address');
$table->string('city');
$table->string('postalcode')->nullable();
$table->string('province');
$table->integer('user_id')->unsigned();
$table->timestamps();
});
Schema::create('addresses', function (Blueprint $table) {
$table->foreign('user_id')->references('id')->on('users');
});
}
我的env
文件连接也是如此:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=testproject
DB_USERNAME=root
DB_PASSWORD=
有什么想法吗?
答案 0 :(得分:0)
我认为对于第二个实例,您应该使用Schema :: table
public function up()
{
Schema::create('addresses', function (Blueprint $table) {
$table->increments('id');
$table->string('address');
$table->string('city');
$table->string('postalcode')->nullable();
$table->string('province');
$table->integer('user_id')->unsigned();
$table->timestamps();
});
Schema::table('addresses', function (Blueprint $table) {
$table->foreign('user_id')->references('id')->on('users');
});
}