[英]Laravel migration error in connection
I try to work on new laravel project and I get error below on php artisan migrate
我尝试在新的laravel项目上工作,并且在
php artisan migrate
migration上收到以下错误
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
What I did so far: 到目前为止,我做了什么:
I added codes below to my AppServiceProvider
我在我的
AppServiceProvider
添加了以下代码
use Illuminate\Support\Facades\Schema;
/////
public function boot()
{
Schema::defaultStringLength(191);
}
And changed this part of my database.php
并更改了我的
database.php
这一部分
'strict' => true,
TO 至
'strict' => false,
And still get the same error. 而且仍然会得到同样的错误。
As it is mentioned in my error code, this is related to my addresses
table. 正如我的错误代码中提到的那样,这与我的
addresses
表有关。 Here it is: 这里是:
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');
});
}
Also my env
file connection is like: 另外我
env
文件连接是这样的:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=testproject
DB_USERNAME=root
DB_PASSWORD=
Any idea? 任何想法?
I think for the second instance you should use Schema::table 我认为对于第二个实例,您应该使用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');
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.