I'm new here and I using the framework laravel with livewire I've 2 tables(voitures and type_voiture).When I want to execute php artisan migrate:fresh --seed I get the error message:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'type_article_id' in 'field list' (SQL: insert into voitures
(nom
, noSerie
, imageUrl
, type_article_id
, estDisponible
, updated_at
, created_at
) values (Will, MMXFRQQC, images/imageplaceholder.png, 1, 1, 2022-08-02 11:06:33, 2022-08-02 11:06:33))
Migration Voitures Schema::enableForeignKeyConstraints(); }
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table("voitures", function(Blueprint $table){
$table->dropForeign("type_voiture_id");
});
Schema::dropIfExists('voitures');
}
}
class CreateTypeVoitureTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('type_voiture', function (Blueprint $table) { $table->id(); $table->string("nom")->unique(); $table->timestamps(); }); }
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('type_voiture');
}
}
Seeders TypeVoiture class TypeVoitureTableSeeder extends Seeder { /** * Run the database seeds. * * @return void */ public function run() { DB::table("type_voiture")->insert([ ["nom"=> "VoitureDeLuxe"], ["nom"=> "pick-up"], ["nom"=> "hybrides"], ["nom"=> "Limousines"] ]);
DB::table("propriete_voitures")->insert([
["nom" => "Marque", "type_voiture_id" => 1],
["nom" => "Kilometrage", "type_voiture_id" => 1],
["nom" => "Prix", "type_voiture_id" => 2],
["nom" => "Libelle", "type_voiture_id" => 2],
["nom" => "Marque", "type_voiture_id" => 3],
]);
the migration to the database was successful:
Migrating: 2021_06_22_044045_create_type_voiture_table Migrated: 2021_06_22_044045_create_type_voiture_table (584.08ms) Migrating: 2021_06_22_044047_create_voitures_table Migrated: 2021_06_22_044047_create_voitures_table (2,039.55ms)
I changed the name "article" to "voiture" and then "type_article" to "Type_voiture" And now that I want to create seeders it doesn't work. please what did i do wrong
CodePudding user response:
public function up()
{
Schema::create('voitures', function (Blueprint $table) {
$table->id();
$table->string("nom")->unique();
$table->string("noSerie")->unique();
$table->string("imageUrl")->nullable();
$table->foreignId("type_voiture_id");
$table->boolean("estDisponible")->default(1);
$table->timestamps();
});
Schema::enableForeignKeyConstraints();
CodePudding user response:
class CreateTypeVoitureTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('type_voiture', function (Blueprint $table) {
$table->id();
$table->string("nom")->unique();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('type_voiture');
}
}