gitlaravelseedinglaravel-translatable

Laravel seeding not working on cloned repository


Database seeding using laravel model factories works perfectly on my local(original) repo/laravel project file, but when I clone the remote from github,seeding throws this error:

Column n ot found: 1054 Unknown column 'hr' in 'field list' (SQL: insert in to categories (slug, hr, de, updated_at, created_at) v alues (CATEGORY-1, Title for category-1 on hr language, Title for category-1 on de language, 2018-07-09 11:19:45, 2018-07-09 11:19:4 5))

Migrations work without a problem, on both local and cloned repo, I use Laravel Translatable package. Fields hr and de are locales

I've tried pushing to remote,but it says that everything is up to date, I've also tried to manually copy the seeder and a factory from local to remote/cloned folder, but it still doesn't work.

(the following files are identical on original and cloned repo)

Database seeder:

public function run()
{
     $this->call([
        LanguagesTableSeeder::class, //works
        CategoriesTableSeeder::class, //error
        MealsTableSeeder::class  //error
     ]);
}

Category seeder:

public function run()
{
    factory(App\Category::class, 5)->create();
}

Category factory:

use Faker\Generator as Faker;

use App\Language;

$factory->define(App\Category::class, function (Faker $faker) {

 static $counter = 1;
 $locales = Language::pluck('lang');
 $data = array('slug' => 'CATEGORY-'.$counter);

 foreach ($locales as $locale) {
    $data[$locale] = [
        'title' => 'Title for category-' .$counter. ' on '. $locale . ' language'
    ];
 }
 $counter++;


return $data;
});

Update:

LanguageTableSeeder:

public function run()
{
    if(!App\Language::count()) {

        $defaultLanguages = array('hr','en','de');

        foreach ($defaultLanguages as $language) {
            App\Language::create([
                'lang' => $language
            ]);
        }
    }
}

Categories migration:

public function up()
{
    Schema::create('categories', function (Blueprint $table) {
        $table->increments('id');
        $table->string('slug');
        $table->timestamps();
    });

     Schema::create('category_translations', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('category_id')->unsigned();
        $table->string('locale')->index();
        $table->string('title');
        $table->unique(['category_id','locale']);
        $table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');
    });
}

Repository link


Solution

  • Ok, so after few hours or trying everything, I kind of found a solution.

    There was something wrong with the vendor dir in the cloned repository.

    When I removed vendor from .gitignore it suddenly started to work,instead of using composer install to create vendor in the clone,I just uploaded the full original vendor to github.