使用 laravel 模型工厂的数据库播种在我的本地(原始)repo/laravel 项目文件上完美运行,但是当我从 github 克隆远程时,播种会引发此错误:
未找到列:1054“字段列表”中的未知列“hr”(SQL:插入到
categories
(、、、、、)值(CATEGORY-1,hr 语言上的类别 1 标题,类别 1上slug
的标题hr
)de 语言, 2018-07-09 11:19:45, 2018-07-09 11:19:4 5))de
updated_at
created_at
在本地和克隆的 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');
});
}