【问题标题】:Laravel seeding not working on cloned repositoryLaravel 播种不适用于克隆的存储库
【发布时间】:2018-07-09 11:43:07
【问题描述】:

使用 laravel 模型工厂的数据库播种在我的本地(原始)repo/laravel 项目文件上完美运行, 但是当我从 github 克隆遥控器时,播种会引发此错误:

第 n 列 未找到:1054“字段列表”中的未知列“hr”(SQL:插入 到categories (slug, hr, de, updated_at, created_at) v alues(CATEGORY-1,关于 hr 语言的类别 1 的标题,用于 关于de语言的类别1,2018-07-09 11:19:45,2018-07-09 11:19:4 5))

迁移工作没有问题,在本地和克隆的 repo 上,我使用 Laravel Translatable 包。 字段 hr 和 de 是语言环境

我尝试推送到远程,但它说一切都是最新的,我还尝试手动将播种机和工厂从本地复制到远程/克隆文件夹,但它仍然不起作用。

(以下文件在原始和克隆 repo 上是相同的)

数据库播种器:

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

分类播种器:

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

类别工厂:

use Faker\Generator as Faker;

使用应用\语言;

$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;
});

更新:

LanguageTableSeeder:

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

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

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

类别迁移:

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

【问题讨论】:

  • 你能比较本地分贝和生产分贝吗?
  • 您能显示categories 表的迁移吗?还有LanguagesTableSeeder.
  • +Jerodev 我将迁移和播种器添加到问题中。
  • +Enrico 是的,我可以,他们是一样的。

标签: git laravel seeding laravel-translatable


【解决方案1】:

好的,经过几个小时或尝试了所有方法后,我找到了解决方案。

克隆存储库中的供应商目录有问题。

当我从 .gitignore 中删除供应商时,它突然开始工作,而不是使用 composer install 在克隆中创建供应商,我只是将完整的原始供应商上传到 github。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-31
    • 1970-01-01
    • 2016-08-24
    • 2021-12-31
    • 1970-01-01
    • 2019-05-09
    • 1970-01-01
    相关资源
    最近更新 更多