Level 1
@burlresearch i want to do like this
CREATE TABLE users (
id integer PRIMARY KEY,
username varchar NOT NULL,
password varchar NOT NULL,
type_id integer NOT NULL,
FOREIGN KEY (type_id) REFERENCES types(id)
);
I have two tables
I am using laravel 5.4 and I want to fill the type_id in user table with data on id in types table, if possible i want to do it on database migration
I have two tables
Types table
id
name
Users table
id
type_id
username
password
Sure - you can set that up with Laravel migrations. The foreign keys are setup as such:
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('username');
$table->string('password');
$table->unsignedInteger('type_id');
$table->foreign('type_id')
->references('id')
->on('types') ;
});
Please or to participate in this conversation.