【发布时间】:2015-09-21 10:47:20
【问题描述】:
[照亮\数据库\查询异常]
SQLSTATE [42000]:语法错误或访问冲突:1064 你有一个错误我
n 你的 SQL 语法;检查与您的 MySQL 服务器相对应的手册 v
在更新 casc 上删除级联时使用正确语法的版本
ade' 在第 1 行(SQL:alter table users 添加约束 users_address_id_fo
在删除级联上统治外键(address_id)引用address()
在更新级联上)
[PDO异常] SQLSTATE [42000]:语法错误或访问冲突:1064 你有一个错误我 n 你的 SQL 语法;检查与您的 MySQL 服务器相对应的手册 v 在更新 casc 上删除级联时使用正确语法的版本 ade' 在第 1 行
迁移 [--bench[="..."]] [--database[="..."]] [--force] [--path[="..."]] [- -pac kage[="..."]] [--pretend] [--seed]
public function up()
{
Schema::create('users',function($table){
$table->increments('id');
$table->string('name',30);
$table->string('phone',11);
$table->integer('age');
$table->string('email',50);
$table->string('marry_status',10);
$table->integer('address_id');
$table->foreign('address_id')->reference('id')->on('address')->onDelete('cascade')->onUpdate('cascade');
$table->integer('points_id');
$table->foreign('points_id')->reference('id')->on('address')->onDelete('cascade')->onUpdate('cascade');
$table->timestamps();
});
}
php 迁移 --pretend
CreateUsersTable: create table `users` (`id` int unsigned not null auto_increment primary key, `name` varchar(30) not null, `phone` varchar(11) not null, `age` int not null, `email` varchar(50) not null, `marry_status` varchar(10) not null, `address_id` int not null, `points_id` int not null, `created_at` timestamp default 0 not null, `updated_at` timestamp default 0 not null) default character set utf8 collate utf8_unicode_ci
CreateUsersTable: alter table `users` add constraint users_address_id_foreign foreign key (`address_id`) references `address` () on delete cascade on update cascade
CreateUsersTable: alter table `users` add constraint users_points_id_foreign foreign key (`points_id`) references `address` () on delete cascade on update cascade
CreateAddressTable: create table `address` (`id` int unsigned not null auto_increment primary key, `users_id` int not null, `name` varchar(30) not null, `created_at` timestamp default 0 not null, `updated_at` timestamp default 0 not null) default character set utf8 collate utf8_unicode_ci
CreatePointsTable: create table `points` (`id` int unsigned not null auto_increment primary key, `point` int not null, `users_id` int not null, `created_at` timestamp default 0 not null, `updated_at` timestamp default 0 not null) default character set utf8 collate utf8_unicode_ci
我尝试了,但我不好
public function up()
{
Schema::create('users',function($table){
$table->increments('id');
$table->string('name',30);
$table->string('phone',11);
$table->integer('age');
$table->string('email',50);
$table->string('marry_status',10);
$table->integer('address_id');
$table->integer('points_id');
$table->timestamps();
});
Schema::table('users',function($table){
$table->foreign('points_id')->references('id')->on('address')->onDelete('cascade')->onUpdate('cascade');
$table->foreign('address_id')->references('id')->on('address')->onDelete('cascade')->onUpdate('cascade');
});
}
【问题讨论】:
-
运行带有
--pretend标志的migrate命令并向我们展示输出。 -
@anh 您的问题下方有一个 edit 链接,使用它来修改问题并在此处包含命令的输出,不要在 cmets 中发布该信息.
-
请用这个输出更新你的问题。它将更具可读性。
-
@anh 你必须在一个完全独立的迁移文件中进行,该文件必须在创建所有表之后。
标签: laravel schema migrate laravel-artisan