Giter Club home page Giter Club logo

laravel-csv-seeder's People

Contributors

giannierrera avatar jeroenzwart avatar petersowah avatar roboonl avatar thegeremy avatar xint0-elab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

laravel-csv-seeder's Issues

convert the void value '' to NULL when is type 'time'

some columns that is of type 'time'
when i dont have value,
put '' but return error because format is '00:00:00'
if i put
$this->defaults = ['time' => NULL ];

some row that have data will be null to,
have some other option change the '' to null ?

Problem parsing CSV file

EDIT: Ah, a silly mistake, I didn't change the delimiter to:
$this->delimiter = ',';

I got this error when I tried to load a CSV file:

CsvSeeder: Found only one column in header, maybe a wrong delimiter (;) for the CSV file was set CsvSeeder: 0 of 586 rows has been seeded in table "list_compounds"

It is definitely delimited by commas, I can parse it with LibreOffice Calc.

Generate slug when importing

Hello,

Is there a way to set the slug from particular fields when importing a csv file?

Example would be:

name,address,city,state,postal
Bob,12345 This Rd,My City,NY,55555

I would like to generate a slug form: name,city,state,postal

I am currently using cviebrock/eloquent-sluggable to generate slugs, which is automated when adding a person to the database. However, when importing slugs are not created.

I see it is possible to set a default for a given column, I have this added to my seeder, which works partially:

$this->defaults = [
    'slug' => SlugService::createSlug(Salon::class, 'slug',  'name')
];

All this does is put: name as the slug, how can I get the name,city,state,postal values when importing to update the slug?

Thank you in advance for any assistance.

Value with 0 changed into null when running db:seed

Hello,

I am using this package to seed my data into DB, it was working months ago with the same CSV. But today, i tried to re-run my seeder and something weird happened.

I have CSV with these data :
id;option;question_number;most;least;type;option_b;question_number_b
1;1;53;A;;C;0;0
2;3;53;C;;C;0;0

But everytime i tried to seed, the seeder always return error
Rows of the file "/database/seeds/csv/TblMTestQuestion.csv" has been failed to insert: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'option_b' cannot be null (SQL: insert into tbl_m_test_questions (created_at, id, least, most, option, option_b, question_number, question_number_b, type, updated_at) values (2020-08-13 13:50:12, 1, ?, A, 1, ?, 53, ?, C, 2020-08-13 13:50:12), (2020-08-13 13:50:12, 2, ?, C, 3, ?, 53, ?, C, 2020-08-13 13:50:12)

I did not intend to seed a null value to the option_b column, i tried to set 0 on the integer field of option_b.

Auto incrementing id

Is there a way to have the id column of the table be auto incremented rather than having to map to an id column in the csv?

Getting Error in $this->outputParsed()

When i try to seed i'm getting
Symfony\Component\Debug\Exception\FatalThrowableError : Call to a member function line() on null

at /Applications/XAMPP/xamppfiles/htdocs/webspa/webapp-spa/vendor/jeroenzwart/laravel-csv-seeder/src/CsvSeeder.php:418
414| if( $level ) $message = '<'.$level.'>'.$message.'</'.$level.'>';
415| if(empty($message)){
416| dd('hi');
417| }

418| dd($message,$this->command->line( 'CsvSeeder: '.$message ));
419| $this->command->line( 'CsvSeeder: '.$message );
420| }
421|
422| }

Exception trace:

1 JeroenZwart\CsvSeeder\CsvSeeder::console("2 of 2 rows has been seeded in table "citizenship"")
/Applications/XAMPP/xamppfiles/htdocs/webspa/webapp-spa/vendor/jeroenzwart/laravel-csv-seeder/src/CsvSeeder.php:388

2 JeroenZwart\CsvSeeder\CsvSeeder::outputParsed()
/Applications/XAMPP/xamppfiles/htdocs/webspa/webapp-spa/vendor/jeroenzwart/laravel-csv-seeder/src/CsvSeeder.php:222

No FOREIGN_KEY_CHECKS configuration in PostgreSQL

First, thanks for the package.

This does not work with PostgreSQL if truncate is set to true. PostgreSQL does not have a FOREIGN_KEY_CHECKS configuration option.

private function truncateTable()
{
if( $this->truncate === FALSE ) return;
if( $this->foreignKeyCheck === FALSE) DB::connection($this->connection)->statement('SET FOREIGN_KEY_CHECKS = 0;');
DB::connection($this->connection)->table( $this->tablename )->truncate();
if( $this->foreignKeyCheck === FALSE ) DB::connection($this->connection)->statement('SET FOREIGN_KEY_CHECKS = 1;');
}

This is the error received:

 SQLSTATE[42704]: Undefined object: 7 ERROR:  unrecognized configuration parameter "foreign_key_checks" (SQL: SET FOREIGN_KEY_CHECKS = 0;)

The workaround is to set $this->truncate = false; in the seeder.

Am I missing something or does this only work with ; separated files?

As the name suggests, commas are the delimiters of choice for comma separated value files.
I can't see a way to change the default delimiter of ";"

As such, I keep getting the error "CsvSeeder: Found only one column in header, maybe a wrong delimiter (;) for the CSV file was set"

seeder not working (csv with 400K rows)

Im working wiht this awesome package in my laravel-zero project but it is not working.
Heres my csvSeed code:

<?php

namespace Database\Seeders;
use Illuminate\Support\Facades\DB;
use JeroenZwart\CsvSeeder\CsvSeeder;

class OrdenesReposicion extends CsvSeeder
{
    public function __construct()
    {
        $this->file = '/database/csvs/abastos/ordenes_reposicion.csv';
        $this->tablename = 'ordenes_reposicion';
        $this->truncate = true;
        $this->delimiter = '~';
        $this->header = true;
        // $this->mapping = [
         //  'clas_ptal_origen',
        //     'nombre_ooad',
        //     'id_ooad',
        //     'clas_ptal_entrega',
        //     'nombre_unidad_entrega',
        //     'numero_contrato',
        //     'numero_licitacion',
        //     'numero_evento_compranet',
        //     'tipo_evento',
        //     'fecha_inicio_contrato',
        //     'fecha_termino_contrato',
        //     'monto_minimo_contrato_sin_iva',
        //     'monto_maximo_contrato_sin_iva',
        //     'cantidad_minima_piezas',
        //     'cantidad_maxima_piezas',
        //     'monto_minimo_clave_sin_iva',
        //     'monto_maximo_clave_sin_iva',
        //     'numero_de_solicitud',
        //     'numero_de_orden_reposicion',
        //     'origen',
        //     'gpo',
        //     'gen',
        //     'esp',
        //     'dif',
        //     'var',
        //     'descripcion_articulo',
        //     'unidad_presentacion',
        //     'cantidad_presentacion',
        //     'tipo_presentacion',
        //     'razon_social',
        //     'rfc_proveedor',
        //     'numero_proveedor',
        //     'fecha_expedicion',
        //     'fecha_www',
        //     'fecha_confirmacion',
        //     'fecha_entrega',
        //     'fecha_atencion',
        //     'fecha_sello_alta_qr',
        //     'fecha_cancelacion',
        //     'fecha_entrega_inicial',
        //     'fecha_entrega_ampliada',
        //     'matricula_usuario_amplio',
        //     'estatus_orden',
        //     'precio_compra',
        //     'iva',
        //     'cantidad_solicitada',
        //     'cantidad_comprometida',
        //     'cantidad_atendida',
        //     'importe_solicitado_iva',
        //     'importe_comprometido_iva',
        //     'importe_atendido_iva',
        //     'importe_solicitado_sin_iva',
        //     'importe_comprometido_sin_iva',
        //     'importe_atendido_sin_iva',
        //     'saldo_contrato',
        //     'saldo_contrato_porcentaje',
        //     'fecha_firma_contrato',
        //     'orden_resguardo',
        //     'clas_ptal_operador_logistico',
        //     'nombre_operador_logistico',
        //     'zona_operador_logistico',
        //     'cantidad_alta_imss',
        //     'fecha_alta_imss',
        // ];

        $this->chunk = 1000;
    }

    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        // Recommended when importing larger CSVs
        DB::disableQueryLog();
        parent::run();
    }
}

The file exists but whenever i run the migrations it just stop on this seeder.

Error: Call to a member function line() on null

Hi,

I'm trying to run a CSV seeder using the package, but having an error being thrown when seeding via a TestCase.

The error I'm getting is:

Error: Call to a member function line() on null
   │
   ╵ /Users/me/Workspaces/php/project/vendor/jeroenzwart/laravel-csv-seeder/src/CsvSeeder.php:458
   ╵ /Users/me/Workspaces/php/project/vendor/jeroenzwart/laravel-csv-seeder/src/CsvSeeder.php:403
   ╵ /Users/me/Workspaces/php/project/vendor/jeroenzwart/laravel-csv-seeder/src/CsvSeeder.php:381
   ╵ /Users/me/Workspaces/php/project/vendor/jeroenzwart/laravel-csv-seeder/src/CsvSeeder.php:262
   ╵ /Users/me/Workspaces/php/project/vendor/jeroenzwart/laravel-csv-seeder/src/CsvSeeder.php:185
   ╵ /Users/me/Workspaces/php/project/Modules/Database/Seeders/Lookups/MyTableSeeder.php:44
   ╵ /Users/me/Workspaces/php/project/vendor/laravel/framework/src/Illuminate/Database/Seeder.php:150
   ╵ /Users/me/Workspaces/php/project/vendor/laravel/framework/src/Illuminate/Database/Seeder.php:49

This is happening in my test case which I've tried two ways of running.

app(DatabaseSeeder::class)->call(MyTableSeeder::class);

This causes the error thrown above.

When running it using

$this->seed(LedgerAccountTypeTableSeeder::class);

I get no error, but the test method is not actually completing and not executing any lines of code after the call to $this->seed

Any ideas what might be the problem?

Seed fails when try to seed from big files.

I'm trying to seed a big (200Mb) CSV file into a table but I keep getting the max memory error. It seems the seeder loads the whole file even if I specify a chunk size. The seed fails on setTotal method, is it possible to get the row total without loading the whole file in memory?

Encoding

Hi, i have csv files encoded in UTF8 and database fields are also UTF8, but the text is not the same as in the csv file. It looks like that your script will not read all characters correcly. Which encoding should the csv file be? For example sting "bežný člen" is read as "bežný Ä�len". Thanks.

Request enable/disable foreign keys checks

There is not able to change the foreign keys checks when truncate table

private function seeding()
    {
        $this->truncateTable();
private function truncateTable( $foreignKeys = TRUE )

Set the Variable with the Path to open multiples CSV

Could there be a loop when execute parent::run(); in DatabaseSeeder.php
to open all CSV in the folder
(like $this->folder = '/database/seeds/csvs/'; )
and not have to set one by one?

(sure the filename of the CSV is the same as the tablename)

Validation Rules

Is there a way to set validation rules using laravel validator?

$this->mapping = ['id', 'zip_code', 'city'];
$this->validation_rules = [
'zip_code' => 'required|unique:zip_codes|min:5|max:5',
'city' => 'required|max:200',
];

How do I specify a different database connection?

I am writing tests for my application and I need to seed data into the default database and one other one. Seeding into the default database is simple enough, but how do I specify a different database connection for the other seeders ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.