lundi 3 septembre 2018

Laravel - errno: 150 Foreign key constraint is incorrectly formed

I want to to make a relation between company model and jobs model But it give me this erorr:

PDOException::("SQLSTATE[HY000]: General error: 1005 Can't create table `my-career`.`#sql-2fd8_ba` (errno: 150 "Foreign key constraint is incorrectly formed")")

Company Model:

class Company extends Model{
    public $table="comppanies";
    public function jobs() {
        return $this->hasMany(App\Job::class);
    }
}

Job Model:

class Job extends Model{
    public $table="jobs";
    public function company() {
        return $this->belongsTo(App\Company::class, 'company_id');
    }
}

Job Table:

public function up()
{
    Schema::create('jobs', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->integer('company_id')->unsigned();
        $table->foreign('company_id')->references('id')->on('company');
    });
}

I dont know where is the problem



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire