1

I am on Ubuntu 20.04 (just upgraded) and with that it changed my mysql version from 5.7.30 to 8.0.20. I created some migrations but when I ran them using artisan, they failed. I then tried to do php artisan migrate:fresh and it dropped all my tables but the migration did not complete. Does anyone know if Ubuntu upgrading my MySQL version to 8+ is indeed the cause of this issue? Nothing else changed. My DB credentials are golden in my .env etc... In the error itself idk why it is trying to make a table with the name of migration.

Error:

php artisan migrate:fresh

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.

Migration One:

<?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');
    }
}

Out of the box User Migration:

<?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');
    }
}

Thank you in advance.

1 Answer 1

1

Go to config/database.php and change:

'engine' => null,

to:

'engine' => 'InnoDB'

Or manually define the engine on every migration:

$table->engine('InnoDB');
Sign up to request clarification or add additional context in comments.

1 Comment

Yep that was the issue, thank you. I also had to run composer dumpautoload

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.