i am student and trying to use laravel for my final year project. i am trying to create a foreign key on a column in the schedules table in my DB,
here is my code for the schedules table:
Schema::create('schedules', function (Blueprint $table) {
$table->increments('schedule_id');
$table->string('bus_number')->unsigned();
$table->foreign('bus_reg_number')->references('bus_reg_number')->on('buses');
$table->string('departure_location');
$table->string('destination_location');
$table->dateTime('departure_time');
$table->date('departure_date');
$table->string('bus_model');
$table->integer('number_of_seats');
$table->float('price', 8, 2);
$table->timestamps();
});
this is the error i get when i run php artisan migrate:
In Connection.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 use near 'unsigned not null, departure_locatio n varchar(191) not null, destination_loca' at line 1 (SQL: create tableschedules(schedule_idint unsigned n ot null auto_increment primary key,bus_numbervarchar(191) unsigned not null,departure_locationvarchar(191) not null,destination_locationvarchar(191) not null,departure_timedatetime not null,departure_datedate n ot null,bus_modelvarchar(191) not null,number_of_seatsint not null,pricedouble(8, 2) not null,created
_attimestamp null,updated_at` timestamp null) default character set utf8mb4 collate utf8mb4_unicode_ci)
In Connection.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 use near 'unsigned not null, departure_locatio n varchar(191) not null, `destination_loca' at line 1
thank you.