繁体   English   中英

连接中的Laravel迁移错误

[英]Laravel migration error in connection

我尝试在新的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

到目前为止,我做了什么:

我在我的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=

任何想法?

我认为对于第二个实例,您应该使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM