I keep getting the following two errors below, when trying to delete a bus model and its only happening on the live version(forge, digital ocean) of a web app which I have built.
Bus has one manufacturer and manufacturer model has many buses, I want to be able to delete a single bus without deleting the manufacturer model and also without removing other buses associated with the manufacturer so cascade on delete doesn't really help as it deletes all the buses connected to the related manufacturer.
Note: It all works offline locally using phpmyadmin, wamp thats what is confusing me, Its my first website that I have put up live so please need some help.
Thanks in advance.
Manufacturer Class
public function buses()
{
return $this->hasMany('App\Bus');
}
Bus Class
public function manufacturer()
{
return $this->belongsTo('App\Manufacturer');
}
Buses Table Migration
Schema::create('buses', function (Blueprint $table)
{
$table->increments('id');
$table->string('title');
$table->integer('manufacturer_id')->unsigned()->default(1);
$table->foreign('manufacturer_id')->references('id')->on('buses');
$table->string('model');
$table->string('registration' , 15);
$table->string('body');
$table->string('chasis');
$table->integer('seating');
$table->integer('standing');
$table->date('reg_date');
$table->date('expiry_date');
$table->string('dda');
$table->text('description');
$table->integer('price');
$table->integer('sold')->default(0);
$table->timestamps();
});
Manufacturers Table Migration
Schema::create('manufacturers', function (Blueprint $table)
{
$table->increments('id');
$table->string('name')->unique();
$table->timestamps();
});
Two Exceptions that keep coming up when attempting to delete bus model
QueryException in Connection.php line 770:
SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (sherwood_cars.buses, CONSTRAINT buses_manufacturer_id_foreign FOREIGN KEY (manufacturer_id) REFERENCES buses (id)) (SQL: delete from buses where id = 1)
PDOException in Connection.php line 505:
SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (sherwood_cars.buses, CONSTRAINT buses_manufacturer_id_foreign FOREIGN KEY (manufacturer_id) REFERENCES buses (id))