tebazil / db-seeder

PHP database seeder. Easily fill your database with fake data. Framework agnostic. Easy to use.
Other
50 stars 15 forks source link

PHP Version & non-Composer setup #16

Open vipers-web-design opened 1 year ago

vipers-web-design commented 1 year ago

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/

vipers-web-design commented 1 year ago

I got Composer set up and working, I'm still getting the one error. Now I'm linking through the autoload script.

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/vendor/tebazil/db-seeder/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] => 161
                    [function] => refill
                    [class] => tebazil\dbseeder\Seeder
                    [type] => ->
                    [args] => Array
                        (
                        )

                )

        )

    [previous:Exception:private] => 
)
vipers-web-design commented 1 year ago

I found the cause, I'm trying to pass a relation id into a column. The data is already in my database from the countries table from this repo https://github.com/dr5hn/countries-states-cities-database.

$seeder = new \tebazil\dbseeder\Seeder($pdo);
$generator = $seeder->getGeneratorConfigurator();
$faker = $generator->getFakerConfigurator();

$seeder->table('users')->columns([
    'userid' => $generator->pk,
    'country' => $generator->relation('countries', 'id')
])->rowQuantity(100);

I'm getting the extra errors;

Notice: Undefined index: countries in /Users/andrewford/Creative Cloud Files/VWD-Active-Portfolio/feedverse.net/vendor/tebazil/db-seeder/src/Seeder.php on line 69

Warning: in_array() expects parameter 2 to be array, null given in /Users/andrewford/Creative Cloud Files/VWD-Active-Portfolio/feedverse.net/vendor/tebazil/db-seeder/src/Seeder.php on line 69

So a workaround is using an anonymous function to get a random number between x & y based on how many rows exist in that table;

'country' => function() {
    return rand(1, 250);
}