라라벨로 배우는 실전 php 웹 프로그래밍 서적으로 독학하고 있는 회사원입니다 ( 물어볼 사람이 없어요 ㅠㅠ)
relationship 에 대해서 공부하는 도중에 실습을 해봤는데 막히는 부분이 있어서 질문드립니다 ㅠㅠ
users 테이블 desc 정보입니다
+----------------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------------+------------------+------+-----+---------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | name | varchar(255) | NO | | NULL | | | email | varchar(255) | NO | UNI | NULL | | | password | varchar(255) | NO | | NULL | | | remember_token | varchar(100) | YES | | NULL | | | created_at | timestamp | YES | | NULL | | | updated_at | timestamp | YES | | NULL | | | confirm_code | varchar(60) | YES | | NULL | | | activated | tinyint(1) | NO | | 0 | | +----------------+------------------+------+-----+---------+----------------+
이 테이블에
아래와 같이 articles 마이그레이션을 만들었습니다
<?php
use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration;
class CreateArticlesTable extends Migration { public function up() { Schema::create('articles', function (Blueprint $table) { $table->increments('id'); $table->integer('user_id')->unsigned()->index(); $table->string('title'); $table->text('content'); $table->timestamps(); $table->foreign('user_id')->reterences('id')->on('users')->onUpdate('cascade')->onDelete('cascade'); }); }
public function down() { Schema::dropIfExists('articles'); } }
그리고 php artisan migrate 를 하면 아래와 같은 오류가 납니다 ㅠㅠ
[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 th e right syntax to use near ') on delete cascade on update cascade' at line 1 (SQL: alter table `articles` add constraint `articles_user_id_foreign` foreign key (`u ser_id`) references `users` () on delete cascade on update cascade)
[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 th e right syntax to use near ') on delete cascade on update cascade' at line 1
오류를 보면 onupdate 랑 delete 에서 문제를 일으키는것 같아서 ㅠㅠ
저부분을 빼고 해봤는데 같은 오류가 나서 아닌거 같고 ,, 마이그레이션 문법이 잘못됬을까요 ?
안녕하세요
라라벨로 배우는 실전 php 웹 프로그래밍 서적으로 독학하고 있는 회사원입니다 ( 물어볼 사람이 없어요 ㅠㅠ)
relationship 에 대해서 공부하는 도중에 실습을 해봤는데 막히는 부분이 있어서 질문드립니다 ㅠㅠ
users 테이블 desc 정보입니다
+----------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(255) | NO | | NULL | |
| email | varchar(255) | NO | UNI | NULL | |
| password | varchar(255) | NO | | NULL | |
| remember_token | varchar(100) | YES | | NULL | |
| created_at | timestamp | YES | | NULL | |
| updated_at | timestamp | YES | | NULL | |
| confirm_code | varchar(60) | YES | | NULL | |
| activated | tinyint(1) | NO | | 0 | |
+----------------+------------------+------+-----+---------+----------------+
이 테이블에
아래와 같이 articles 마이그레이션을 만들었습니다
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateArticlesTable extends Migration
{
public function up()
{
Schema::create('articles', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned()->index();
$table->string('title');
$table->text('content');
$table->timestamps();
$table->foreign('user_id')->reterences('id')->on('users')->onUpdate('cascade')->onDelete('cascade');
});
}
public function down()
{
Schema::dropIfExists('articles');
}
}
그리고 php artisan migrate 를 하면 아래와 같은 오류가 납니다 ㅠㅠ
[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 th
e right syntax to use near ') on delete cascade on update cascade' at line 1 (SQL: alter table `articles` add constraint `articles_user_id_foreign` foreign key (`u
ser_id`) references `users` () on delete cascade on update cascade)
[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 th
e right syntax to use near ') on delete cascade on update cascade' at line 1
오류를 보면 onupdate 랑 delete 에서 문제를 일으키는것 같아서 ㅠㅠ
저부분을 빼고 해봤는데 같은 오류가 나서 아닌거 같고 ,, 마이그레이션 문법이 잘못됬을까요 ?
이렇게 오류가 나는데 데이터베이스에서 articles 테이블을 만들어져 있습니다ㅠㅠ
도움좀 주시면 안될까요ㅠ ㅠ?