laravel-seeding

Laravel: Seeding multiple unique columns with Faker

末鹿安然 提交于 2020-12-30 06:36:28
问题 Introduction What up folks, I got a question about model factories and multiple unique columns: Background I have a model named Image. This model has language support stored in a separate model, ImageText . ImageText has an image_id column, a language column and a text column. ImageText has a constraint in MySQL that the combination image_id and language has to be unique. class CreateImageTextsTable extends Migration { public function up() { Schema::create('image_texts', function ($table) { .

Laravel: Seeding multiple unique columns with Faker

旧街凉风 提交于 2020-12-30 06:33:46
问题 Introduction What up folks, I got a question about model factories and multiple unique columns: Background I have a model named Image. This model has language support stored in a separate model, ImageText . ImageText has an image_id column, a language column and a text column. ImageText has a constraint in MySQL that the combination image_id and language has to be unique. class CreateImageTextsTable extends Migration { public function up() { Schema::create('image_texts', function ($table) { .

Laravel 5.3 db:seed command simply doesn't work

杀马特。学长 韩版系。学妹 提交于 2020-01-01 01:26:06
问题 I do everything by-the-book: Installed fresh Laravel 5.3.9 app (all my non-fresh apps produce the same error) run php artisan make:auth create migrations for a new table `php artisan make:migration create_quotations_table --create=quotations Schema::create('quotations', function (Blueprint $table) { $table->increments('id'); $table->string('text'); // my problem persists even with the below two columns commented out $table->integer('creator_id')->unsigned()->index('creator_id'); $table-

Laravel 5.3 db:seed command simply doesn't work

拈花ヽ惹草 提交于 2020-01-01 01:26:05
问题 I do everything by-the-book: Installed fresh Laravel 5.3.9 app (all my non-fresh apps produce the same error) run php artisan make:auth create migrations for a new table `php artisan make:migration create_quotations_table --create=quotations Schema::create('quotations', function (Blueprint $table) { $table->increments('id'); $table->string('text'); // my problem persists even with the below two columns commented out $table->integer('creator_id')->unsigned()->index('creator_id'); $table-

How to seed multiple relationships in Laravel with Faker

家住魔仙堡 提交于 2019-12-25 03:13:55
问题 I have a database with two columns, brands and shops. Each brand can owe several shops, and I want to seed my database via Fakers using Laravel. So after setting up the migrations and the relationships in the models <?php namespace App; use Illuminate\Database\Eloquent\Model; class Brand extends Model { /** * Get the shops for the brand. */ public function shops() { return $this->hasMany('App\Shop','sh_brand_id'); } } And: <?php namespace App; use Illuminate\Database\Eloquent\Model; class

Laravel 4 Database insert Error - preg_replace(): Parameter mismatch, pattern is a string while replacement is an array

空扰寡人 提交于 2019-12-24 11:42:31
问题 In database seeder, I just want to insert some hard-coded data to the table. $Pro1_id = DB::table('projects')->select('id')->where('projectName', '=', 'Project A')->get(); $data1_1 = array( 'id' => 1, 'projectID' => $Pro1_id, 'attributeID' => 1, 'levelID' => 2, 'percentage' => 20, 'risk_value' => 25186.86311, 'expectation_value' => 706455.9401, ); $data1_2 = array( 'projectID' => $Pro1_id, 'attributeID' => 2, 'levelID' => 1, 'percentage' => 60, 'risk_value' => 530351.3397, 'expectation_value'

Laravel Factory: Manual Increment of Column

こ雲淡風輕ζ 提交于 2019-12-23 11:56:18
问题 For the following factory definition, the column order needs to be sequential. There is already a column id that is auto-incremented. The first row's order should start at 1 and each additional row's order should be the next number ( 1 , 2 , 3 , etc.) $factory->define(App\AliasCommand::class, function (Faker\Generator $faker) { return [ 'user_id' => App\User::inRandomOrder()->first()->id, 'command' => $faker->word, 'content' => $faker->sentence, 'order' => (App\AliasCommand::count()) ? App

Laravel Factory: Manual Increment of Column

冷暖自知 提交于 2019-12-23 11:56:16
问题 For the following factory definition, the column order needs to be sequential. There is already a column id that is auto-incremented. The first row's order should start at 1 and each additional row's order should be the next number ( 1 , 2 , 3 , etc.) $factory->define(App\AliasCommand::class, function (Faker\Generator $faker) { return [ 'user_id' => App\User::inRandomOrder()->first()->id, 'command' => $faker->word, 'content' => $faker->sentence, 'order' => (App\AliasCommand::count()) ? App

Laravel 5.1 Migration and Seeding Cannot truncate a table referenced in a foreign key constraint

谁都会走 提交于 2019-12-18 12:52:28
问题 I'm trying to run the migration (see below) and seed the database, but when I run php artisan migrate --seed I get this error: Migration table created successfully. Migrated: 2015_06_17_100000_create_users_table Migrated: 2015_06_17_200000_create_password_resets_table Migrated: 2015_06_17_300000_create_vehicles_table [Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1701 Cannot truncate a table referenced in a foreign key constraint (`app`.`vehicles`,

Defining Laravel foreign keys with Model Factories, One to One & One to Many Relationships without creating unnecessary models

只谈情不闲聊 提交于 2019-12-12 08:35:14
问题 Recently I have been trying to seed my database using Laravel seeding through Model Factories and Faker. For simple schemas, it is just a breeze to have it working :). However, I have encountered several problems when working with complex DB schemas which involve foreign keys and table relationships : One to One One to Many Many to Many ...Like the one described in the link: Laravel 5.1 foreign keys in model factory. In this topic, the official documentation suggests to run the database seeds