簡體   English   中英

無法使用 MYSQL8 遷移 Laravel 中的表

[英]Unable to Migrate Tables In Laravel using MYSQL8

我在 Ubuntu 20.04(剛剛升級)上,因此它將我的 mysql 版本從 5.7.30 更改為 8.0.20。 我創建了一些遷移,但是當我使用工匠運行它們時,它們失敗了。 然后我嘗試執行php artisan migrate:fresh並刪除了我所有的表,但遷移沒有完成。 有誰知道 Ubuntu 將我的 MySQL 版本升級到 8+ 確實是這個問題的原因嗎? 其他一切都沒有改變。 我的數據庫憑據在 my.env 等中是金色的......在錯誤本身中,我知道為什么它試圖創建一個名為migration的表。

錯誤:

php 工匠遷移:新鮮

Dropped all tables successfully.

   Illuminate\Database\QueryException  : 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 the right syntax to use near 'null' at line 1 (SQL: create table `migrations` (`id` int unsigned not null auto_increment primary key, `migration` varchar(255) not null, `batch` int not null) default character set utf8 collate 'utf8_unicode_ci' engine = null)

  at /home/projects/inquiry-app/vendor/laravel/framework/src/Illuminate/Database/Connection.php:669
    665|         // If an exception occurs when attempting to run a query, we'll format the error
    666|         // message to include the bindings with SQL, which will make this exception a
    667|         // lot more helpful to the developer instead of just the database's errors.
    668|         catch (Exception $e) {
  > 669|             throw new QueryException(
    670|                 $query, $this->prepareBindings($bindings), $e
    671|             );
    672|         }
    673| 

  Exception trace:

  1   Doctrine\DBAL\Driver\PDOException::("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 the right syntax to use near 'null' at line 1")
      /home/projects/inquiry-app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:63

  2   PDOException::("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 the right syntax to use near 'null' at line 1")
      /home/projects/inquiry-app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:61

  Please use the argument -v to see more details.

遷移一:

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateQuestionsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('questions', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('title');
            $table->string('slug')->unique();
            $table->text('body');
            $table->unsignedBigInteger('views')->default(0);
            $table->unsignedBigInteger('answers')->default(0);
            $table->integer('votes')->default(0);
            $table->unsignedBigInteger('best_answer_id')->nullable();
            //Foreign Key
            $table->unsignedBigInteger('user_id');
            $table->timestamps();

            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('questions');
    }
}

開箱即用的用戶遷移:

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}

先感謝您。

Go 到config/database.php並更改:

'engine' => null,

至:

'engine' => 'InnoDB'

或者在每次遷移時手動定義引擎:

$table->engine('InnoDB');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM