I have limited knowledge of Laravel, PHP and MySql. I am trying to set up a database with 3 connected tables, using foreign keys. I did this manually in WorkBench MySql before, but I can't make it in Laravel. Here is my error and my code.
SQL STATE[42000]: Syntax error or access violation: 1072 Key column 'cat_id
' doesn't exist in table (SQL: alter table `users` add index `users_cat_id
_usr_id_index`(`cat_id`, `usr_id`))
Table 1
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('usr_id')->autoIncrement();
$table->string('usr_email',45)->unique();
$table->string('usr_password',256);
$table->rememberToken();
$table->string('usr_name',45);
$table->string('usr_surname',45);
$table->string('usr_title',45);
$table->string('usr_psc',5);
$table->string('usr_region',128);
$table->string('usr_adress',128);
$table->string('usr_tel',10);
$table->string('usr_tel_int',13);
$table->binary('usr_image');
$table->tinyInteger('usr_type');
$table->index(['cat_id','usr_id'])->nullable();
$table->index(['tem_id','usr_id'])->nullable();
});
}
Table 2
public function up()
{
Schema::create('category', function (Blueprint $table) {
$table->primary('cat_id');
$table->string('cat_name',45);
});
Schema::table('category', function(Blueprint $table) {
$table->foreign('cat_id')->references('cat_id')->on('users');
});
}
Table 3
public function up()
{
Schema::create('team', function (Blueprint $table) {
$table->increments('tem_id');
$table->unique('tem_sub_id');
$table->string('tem_name',45);
$table->string('tem_subteam_name',45);
});
Schema::table('team', function(Blueprint $table) {
$table->foreign('tem_id')->references('tem_id')->on('users');
});
}