I have three tables in mysql and i want to create 3 migrations in laravel 5.4 but i am not sure if this is the correct way to do it
CREATE TABLE `make_years` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`year` int(11) NOT NULL,
`make_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `compositeIndex` (`year`,`make_id`),
KEY `make_id` (`make_id`),
CONSTRAINT `make_years_ibfk_1` FOREIGN KEY (`make_id`) REFERENCES `makes` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `makes` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `models` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`makeyear_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `compositeIndex` (`name`,`makeyear_id`),
KEY `makeyear_id` (`makeyear_id`),
CONSTRAINT `models_ibfk_1` FOREIGN KEY (`makeyear_id`) REFERENCES `make_years` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
and the migrations that i made are:
Schema::table('make_years', function (Blueprint $table) {
$table->increments('id');
$table->integer('year');
$table->integer('make_id')->unsigned()->nullable();
$table->foreign('make_id')->references('id')->on('makes')->onDelete('set null')->onUpdate('cascade');
$table->engine = 'InnoDB';
});
Schema::table('makes', function (Blueprint $table) {
$table->increments('id');
$table->string('name')->unique();
$table->engine = 'InnoDB';
});
Schema::table('models', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->integer('makeyear_id')->unsigned()->nullable();
$table->unique(array('name', 'makeyear_id'));
$table->foreign('makeyear_id')->references('id')->on('make_years')->onDelete('set null')->onUpdate('cascade');
$table->engine = 'InnoDB';
});
Can anyone know that the migration that i made are correct?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2u8xDXa
via IFTTT
Aucun commentaire:
Enregistrer un commentaire