programing

SQLSTATE[42000]:구문 오류 또는 액세스 위반: 마이그레이션에서 Laravel 및 MariaDB 오류 1064

lastcode 2023. 8. 25. 23:42
반응형

SQLSTATE[42000]:구문 오류 또는 액세스 위반: 마이그레이션에서 Laravel 및 MariaDB 오류 1064

환경:

라라벨 5.5.44

MariaDB 10.4.7

마이그레이션을 실행하려고 하는데 하나의 테이블에서만 다음 오류가 발생합니다.마이그레이션 코드는 다음과 같습니다.

<?php

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

class CreateVehicleTable extends Migration
{

    use SoftDeletes;

    public function up()
    {
        Schema::create('vehicles', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('risk_id')->unsigned()->nullable();
            $table->integer('b7code')->unsigned()->nullable();
            $table->integer('b7type')->unsigned()->nullable();
            $table->string('b7class', 2)->nullable();
            $table->string('b7pgclass', 2)->nullable();
            $table->string('brand', 50)->nullable();
            $table->string('model', 100)->nullable();
            $table->string('version', 250)->nullable();
            $table->string('plate', false)->nullable();
            $table->integer('price')->unsigned()->nullable()->default(null);
            $table->string('frame', 100)->nullable();
            $table->integer('power')->unsigned()->nullable()->default(null);
            $table->integer('engine_capacity')->unsigned()->nullable()->default(null);
            $table->integer('vehicle_category_id')->unsigned()->nullable();
            $table->date('registration_date')->nullable();
            $table->char('usage', 1)->default('P')->nullable();
            $table->integer('circulation_region_id')->unsigned()->nullable();
            $table->string('accessories', false)->nullable();
            $table->timestamps();
            $table->softDeletes();
        });
    }

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

실행 결과는 다음과 같습니다.

연결 중.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 MariaDB server version for the right syntax to us  
  e near ') default character set latin1 collate latin1_general_ci' at line 1 (SQL: create table `vehicles` () default character set latin1 collate latin1_general_ci)  

연결 중.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 MariaDB server version for the right syntax to us  
  e near ') default character set latin1 collate latin1_general_ci' at line 1

라라벨에서 마이그레이션을 실행했는데 잘 작동했습니다.전체 쿼리를 검색하여 표시되는 내용을 확인할 수 있습니다.

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

use Illuminate\Support\Facades\DB;

class CreateVehicleTable extends Migration
{

     use SoftDeletes;

    public function up()
    {
        Schema::create('vehicles', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('risk_id')->unsigned()->nullable();
            $table->integer('b7code')->unsigned()->nullable();
            $table->integer('b7type')->unsigned()->nullable();
            $table->string('b7class', 2)->nullable();
            $table->string('b7pgclass', 2)->nullable();
            $table->string('brand', 50)->nullable();
            $table->string('model', 100)->nullable();
            $table->string('version', 250)->nullable();
            $table->string('plate', false)->nullable();
            $table->integer('price')->unsigned()->nullable()->default(null);
            $table->string('frame', 100)->nullable();
            $table->integer('power')->unsigned()->nullable()->default(null);
            $table->integer('engine_capacity')->unsigned()->nullable()>default(null);
            $table->integer('vehicle_category_id')->unsigned()->nullable();
            $table->date('registration_date')->nullable();
            $table->char('usage', 1)->default('P')->nullable();
            $table->integer('circulation_region_id')->unsigned()->nullable();
            $table->string('accessories', false)->nullable();
            $table->timestamps();
            $table->softDeletes();

            DB::listen(function($query) {           
                var_dump( $query->sql . ' [' . implode(', ', $query->bindings) . 
            ']');

            }); 

         });
    }

데이터 정렬이 다른 경우 다음을 확인해야 합니다.

create table `vehicles` 
(`id` int unsigned not null auto_increment primary key,
`risk_id` int unsigned null,
`b7code` int unsigned null,
`b7type` int unsigned null,
`b7class` varchar(2) null,
`b7pgclass` varchar(2) null,
`brand` varchar(50) null,
`model` varchar(100) null,
`version` varchar(250) null,
`plate` varchar(191) null,
`price` int unsigned null,
`frame` varchar(100) null,
`power` int unsigned null,
`engine_capacity` int unsigned null,
`vehicle_category_id` int unsigned null, 
`registration_date` date null, 
`usage` char(1) null default 'P',
`circulation_region_id` int unsigned null,
`accessories` varchar(191) null,
`created_at` timestamp null,
`updated_at` timestamp null,
`deleted_at` timestamp null)
default character set utf8mb4 collate 'utf8mb4_unicode_ci'

디버깅을 쉽게 할 수 있도록 mysql 또는 phpMyAdmin에서 직접 실행합니다.

언급URL : https://stackoverflow.com/questions/57322967/sqlstate42000-syntax-error-or-access-violation-1064-in-laravel-and-mariadb-e

반응형