tebazil / db-seeder Goto Github PK
View Code? Open in Web Editor NEWPHP database seeder. Easily fill your database with fake data. Framework agnostic. Easy to use.
License: Other
PHP database seeder. Easily fill your database with fake data. Framework agnostic. Easy to use.
License: Other
We have multiple tables with different primary key column than "id", e.g. "aid" or "qid". Looking at tebazil/db-seeder/src/TableConfigurator.php, line 45, Generator::PK only works for columns named "id"? Can we add a new feature to configure this column?
Hi, I have a problem.
When I run the seeder script it stops and shows an error when it tries to use the relation function.
Terminal:
Fatal error: Uncaught InvalidArgumentException: Table data for table quality_list column id is not found in class instance. Probably this is a bug. in /project/vendor/tebazil/db-seeder/src/Generator.php:57
Stack trace:
#0 /project/vendor/tebazil/db-seeder/src/Table.php(149): tebazil\dbseeder\Generator->getValue(Array)
#1 /project/vendor/tebazil/db-seeder/src/Table.php(82): tebazil\dbseeder\Table->fillFromGenerators(Array)
#2 /project/vendor/tebazil/db-seeder/src/Seeder.php(50): tebazil\dbseeder\Table->fill()
#3 /project/seeder.php(67): tebazil\dbseeder\Seeder->refill()
#4 {main}
thrown in /project/vendor/tebazil/db-seeder/src/Generator.php on line 57
PHP code:
...
// Media
$seeder->table('media')->columns([
'duration' => $faker->numberBetween(60, 180),
'imdb_id' => 'tt'.$faker->numberBetween(1000000, 9999999),
'release_date' => $faker->dateTimeThisDecade(),
'rating' => $faker->randomFloat(1, 0, 10),
'summary' => $faker->text(),
'dirname' => $faker->text(),
'tmdb_poster_url' => $faker->url(),
'quality_id' => $generator->relation('quality_list', 'id'), // <- stops here
'added_by_user_id' => $generator->relation('users', 'id'),
'type_id' => $generator->relation('media_types', 'id'),
'status_id' => $generator->relation('media_status', 'id')
])->rowQuantity(150);
// Empty database and fill
$seeder->refill();
I am trying to seed my db but I cant seem to seed every column in a table. I can seed it with 17 columns, but once I try to add an 18th column not gets inserted into the table. in the console t looks like everything is working but when I refresh the db there is nothing in the table.
$seeder->table('applications')->columns(
[
'id', //automatic pk
'submitted_at'=>$faker->dateTimeThisDecade($max = 'now', $timezone = null),
'submitted_at'=>null,
'applicant_ip'=>$faker->ipv4,
'sex_type'=>$faker->randomElement(['f','m','u']),
'ethnic_type'=>$faker->randomElement(['u','m','a','h','w','b','i',]),
'vet'=>$faker->randomElement(['v','u','s','p','0',null,]),
'veta'=>$faker->randomElement(['u','s','p','m',0,null,]),
'is_vet_2014'=>$faker->randomElement([2,1,0,null]),
'is_disabled'=>$faker->randomElement([2,1,0,null]),
'dob'=>(string)$faker->dateTimeThisCentury($max = 'now', $timezone = null),
'archived_at'=>(string)$faker->dateTimeThisDecade($max = 'now', $timezone = null),
'archived_at'=>(string)$faker->dateTimeThisDecade($max = 'now', $timezone = null),
'started_at_server'=>(string)$faker->dateTimeThisDecade($max = 'now', $timezone = null),
'started_at_local'=>(string)$faker->dateTimeThisDecade($max = 'now', $timezone = null),
'completed_at'=>(string)$faker->dateTimeThisDecade($max = 'now', $timezone = null),
'custom_questions'=>$faker->randomElement([0,1]),
//'discloure_agreed_at'=>(string)$faker->dateTimeThisDecade($max = 'now', $timezone = null),
])->rowQuantity(3);
when I uncomment the last table, nothing gets inserted. Also it doesn't consistently insert the number of rows I'm asking it to when it does insert. With this code sometimes it only adds 2 rows instead of three.
There is truncate table in seeder but i want add new entry into existing table how can i disable truncate table or add new record without truncate table.
What minimum version of PHP is supported?
And how about having this work for people to don't use Composer?
Old fashion, manual installation. Is there a correct order?
require_once 'assets/libs/backend/Faker-master/src/autoload.php';
require_once 'assets/libs/backend/db-seeder-master/src/DbHelper.php';
require_once 'assets/libs/backend/db-seeder-master/src/Generator.php';
require_once 'assets/libs/backend/db-seeder-master/src/GeneratorConfigurator.php';
require_once 'assets/libs/backend/db-seeder-master/src/FakerConfigurator.php';
require_once 'assets/libs/backend/db-seeder-master/src/Table.php';
require_once 'assets/libs/backend/db-seeder-master/src/TableConfigurator.php';
require_once 'assets/libs/backend/db-seeder-master/src/Seeder.php';
I'm getting the error;
Exception Object
(
[message:protected] => Something unexpected happened: some tables possibly cannot be filled
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => /Users/andrewford/Creative Cloud Files/VWD-Active-Portfolio/feedverse.net/assets/libs/backend/db-seeder-master/src/Seeder.php
[line:protected] => 46
[trace:Exception:private] => Array
(
[0] => Array
(
[file] => /Users/andrewford/Creative Cloud Files/VWD-Active-Portfolio/feedverse.net/faker.php
[line] => 159
[function] => refill
[class] => tebazil\dbseeder\Seeder
[type] => ->
[args] => Array
(
)
)
)
[previous:Exception:private] =>
)
At first, I was going to focus on 4 tables but was getting the error above.
Then I thought focusing on one table at a time would be okay, except I'm still getting the error.
On line 45 of Seeder.php, I manually added space between the operator if($foolProofCounter++ > 500)
in case if my parser was having a hard time reading the ++>
.
I'm following this tutorial; https://smarttutorials.net/seedpopulate-mysql-database-dummytest-data-using-php-db-seeder/
I'd like to see a feature to pick all elements from a bag or set, but never take a single element twice. This is useful for primary keys and foreign keys, where you want, say, 10 parent elements and 100 child element distributed equally to the parent elements.
class FakerController extends Controller {
public function actionFaker() {
$pdo = new \PDO('mysql:localhost;dbname=mafia-yii', 'mafia-yii', 'cantsay');
$seeder = new \tebazil\dbseeder\Seeder($pdo);
$generator = $seeder->getGeneratorConfigurator();
$faker = $generator->getFakerConfigurator();
$seeder->table('user')->columns([
'username' => $faker->userName,
'email' => $faker->email,
'realName' => $faker->firstName,
'lastName' => $faker->lastName,
'sex' => $faker->randomElement($array = array ('Woman','Man','Other gender')),
'birthDate' => $faker->date($format = 'Y-m-d', $max = '-12 years'),
'country' => $faker->country,
'area' => $faker->state,
'city' => $faker->city,
'password' => Yii::$app->getSecurity()->generatePasswordHash('mDK#x9MX%P4r8#P'),
'secret_question' => 'Your mother maiden name?',
'secret_question_answer' => Yii::$app->getSecurity()->generatePasswordHash('Blank'),
'auth_key' => Yii::$app->getSecurity()->generateRandomString(),
'status' => 10,
])->rowQuantity(30);
$seeder->refill();
}
}
renders:
Executing "TRUNCATE TABLE user" >>> Executing "INSERT INTO user(username, email, realName, lastName, sex, birthDate, country, area, city, password, secret_question, secret_question_answer, auth_key, status) VALUES (:username, :email, :realName, :lastName, :sex, :birthDate, :country, :area, :city, :password, :secret_question, :secret_question_answer, :auth_key, :status)" with params: (:username => maximo.little, :email => [email protected], :realName => Dortha, :lastName => Rempel, :sex => Other gender, :birthDate => 1974-04-18, :country => French Guiana, :area => Nevada, :city => Corenebury, :password => $2y$13$igPNashDFAsEIVtOzp5T6uMHvkCveee52z06E6HrpWzkBsTrL8F66, :secret_question => Your mother maiden name?, :secret_question_answer => $2y$13$JyJyPkz2PgIH3V8idobF5OU8XUq/xHmReSA46GzBaCeIVQRaC5k7S, :auth_key => V4Q8gKRwoGmYTIlkPYoYKiHqD4rgRSI_, :status => 10) >>> Executing "INSERT INTO user(username, email, realName, lastName, sex, birthDate, country, area, city, password, secret_question, secret_question_answer, auth_key, status) VALUES (:username, :email, :realName, :lastName, :sex, :birthDate, :country, :area, :city, :password, :secret_question, :secret_question_answer, :auth_key, :status)" with params: (:username => gregorio14, :email => [email protected], :realName => Everett, :lastName => Stracke, :sex => Man, :birthDate => 1983-08-11, :country => Puerto Rico, :area => New Mexico, :city => Jarretfort, :password => $2y$13$igPNashDFAsEIVtOzp5T6uMHvkCveee52z06E6HrpWzkBsTrL8F66, :secret_question => Your mother maiden name?, :secret_question_answer => $2y$13$JyJyPkz2PgIH3V8idobF5OU8XUq/xHmReSA46GzBaCeIVQRaC5k7S, :auth_key => V4Q8gKRwoGmYTIlkPYoYKiHqD4rgRSI_, :status => 10) >>>
.....and so on
but nothing inserted in database
I have created a seeder for my db. The problem I am getting is that when I use $faker = $generator->getFakerConfigurator();
Instance I am able to add providers in it like book provider etc but in that case, the seeder generates same data for each row. Likewise, when I use the faker wrapper it does not allow me to add any faker provider however, It does generate the unique data for each row. Can you tell me how to add faker providers with db-seeder faker wrapper? or generate unique data with original faker instance.
Thanks in advance.
You added optional and unique but not valid, for some reason. :)
Simple PR, if you would accept it.
lib "fzaninotto/faker" is under public archive status . yii2-facker use the "fakerphp/faker" instead .
Hello!
First of all, thank you for your work! :)
I have a problem. I'd like to insert into the same table multiple times like:
$seeder->table('offer')->columns([
'id',
'type' => 'time',
'publisher_id',
'name' => $faker->catchPhrase,
'name_local' => $faker->catchPhrase,
'description' => $faker->realText(),
'description_local' => $faker->realText(),
'price' => $faker->numberBetween(),
'min_av' => $faker->optional()->numberBetween(),
'max_av' => $faker->optional()->numberBetween(),
'active' => 1,
])->rowQuantity(25);
$seeder->table('offer')->columns([
'id',
'type' => 'av',
'publisher_id',
'name' => $faker->catchPhrase,
'name_local' => $faker->catchPhrase,
'description' => $faker->realText(),
'description_local' => $faker->realText(),
'price' => $faker->numberBetween(0, 5000),
'min_av' => $faker->optional()->numberBetween(0, 100000),
'active' => 1,
])->rowQuantity(25);
It's because different type of offer needs different kind of data.
I get this error:
Something unexpected happened: some tables possibly cannot be filled
Can somebody help me figure it out? :)
Thanks in advance!
Hello, is this a possible to prevent truncate table on refill? An error occurs when I try to populate data tables, which has foreign keys. May be there are another ways to do it?
I m getting the following error when i run db seed
'Object of class DateTime could not be converted to string'
following is my seed
$seeder->table('book')->columns([
'id',
'name'=>$faker->text(20),
'updated'=>$faker->dateTime,
])->rowQuantity(3000);
Hi, how can I create seeder for relation with junction table?
CREATE TABLE `video` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
CREATE TABLE `tag` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
CREATE TABLE `tag_video` (
`tag_id` int(11) NOT NULL,
`video_id` int(11) NOT NULL,
PRIMARY KEY (`tag_id`,`video_id`),
KEY `idx-tag_video-tag_id` (`tag_id`),
KEY `idx-tag_video-video_id` (`video_id`),
CONSTRAINT `fk-tag_video-tag_id` FOREIGN KEY (`tag_id`) REFERENCES `tag` (`id`) ON DELETE CASCADE,
CONSTRAINT `fk-tag_video-video_id` FOREIGN KEY (`video_id`) REFERENCES `video` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
I've tried:
$seeder->table('tag')->data([
[1, 'PHP'],
[2, 'POO'],
[3, 'Java'],
[5, 'Javascript']
], ['id', 'name'])->rowQuantity(5);
$seeder->table('video')->columns([
'id',
'name'=> $faker->sentence(6),
])->rowQuantity(50);
$seeder->table('tag_video')->columns([
'tag_id' => [Generator::RELATION, 'tag', 'id'],
'video_id' => [Generator::RELATION, 'video', 'id'],
]);
But I'm getting duplicated entry for N - N for 'PRIMARY'
Folliwing line generates error:
$seeder = new \tebazil\dbseeder\Seeder($this->con);
PHP Fatal error: Uncaught Error: Class 'tebazil\dbseeder\Seeder' not found in /home/work...
Composer put db-seeder under: vendor/tebazil/db-seeder/src/Seeder.php
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.