簡體   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