반응형
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
반응형
'programing' 카테고리의 다른 글
Opensl : "인증서 체인의 자체 서명된 인증서" 오류 (0) | 2023.08.25 |
---|---|
XHR에 대한 404 오류 감지 (0) | 2023.08.25 |
ORA-01735: 잘못된 ALTER TABLE 옵션 - Toad (0) | 2023.08.25 |
PowerShell을 사용하여 XSD에 대해 XML 파일의 유효성을 검사하는 방법은 무엇입니까? (0) | 2023.08.25 |
숫자 키패드의 keyCode 값? (0) | 2023.08.25 |