rap2hpoutre / fast-excel

🦉 Fast Excel import/export for Laravel
MIT License
2.11k stars 247 forks source link

Invalid text representation: 7 ERROR: input syntax is invalid for integer #167

Closed mojedar closed 4 years ago

mojedar commented 4 years ago

Hi, I am trying to import 130k rows from a csv file, with this library, it is worth mentioning that I can import it with laravel-excel but it takes a long time and that's why I wanted to try this library

But it is giving me the following error: "SQLSTATE[22P02]: Invalid text representation: 7 ERROR: la sintaxis de entrada no es válida para integer: «» (SQL: insert into "uso_suelo" ("cod_pais", "cod_fundo", "nom_fundo", "cod_uso_suelo", "dsc_uso_suelo", "cod_rodal", "cod_especie", "dsc_especie", "ano_plantacion", "cod_esquema", "dsc_esquema", "dsc_restriccion_suelo", "sup_ha", "cod_z_cpino", "cod_z_prod", "cod_sz_prod", "dsc_sz_prod", "id_area_us", "updated_at", "created_at") values (90, 5469, LOS QUILLAYES, 4050, CORTAFUEGO, , , , , , , SIN RESTRICCION, 0.2, 7, 4, 17, NAHUELBUTA INTERIOR ALTA, 32318, 2020-04-28 18:40:07, 2020-04-28 18:40:07) returning "id") I repeat, this does not happen to me with laravel-excel

       $usoSuelo = (new FastExcel)->import(storage_path('/app/uso_suelo3.csv'), function ($line) {
            //dd($users);
            return UsoSuelo::create([
                'cod_pais'     => $line['COD_PAIS'],
                'cod_fundo'     => $line['COD_FUNDO'],
                'nom_fundo'     => $line['NOM_FUNDO'],
                'cod_uso_suelo'     => $line['COD_USOSUELO'],
                'dsc_uso_suelo'     => $line['DSC_USOSUELO'],
                'cod_rodal'     => $line['COD_RODAL'],
                'cod_especie'     => $line['COD_ESPECIE'],
                'dsc_especie'     => $line['DSC_ESPECIE'],
                'ano_plantacion'     => $line['ANO_PLANTACION'],
                'cod_esquema'     => $line['COD_ESQUEMA'],
                'dsc_esquema'     => $line['DSC_ESQUEMA'],
                'dsc_restriccion_suelo'     => $line['DSC_RESTRICCION_SUELO'],
                'sup_ha'    => $line['SUP_HA'], 
                'cod_z_cpino'    => $line['COD_Z_CPINO'],
                'cod_z_prod'    => $line['COD_Z_PROD'], 
                'cod_sz_prod' => $line['COD_SZ_PROD'],
                'dsc_sz_prod' => $line['DSC_SZ_PROD'],
                'id_area_us' => $line['ID_AREA_US']
            ]);
        });

This is my migration

        Schema::create('uso_suelo', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('cod_pais')->nullable();
            $table->integer('cod_fundo')->nullable();
            $table->string('nom_fundo',100)->nullable();
            $table->integer('cod_uso_suelo')->nullable();
            $table->string('dsc_uso_suelo',100)->nullable();
            $table->integer('cod_rodal')->nullable();
            $table->integer('cod_especie')->nullable();
            $table->string('dsc_especie',100)->nullable();
            $table->integer('ano_plantacion')->nullable();
            $table->integer('cod_esquema')->nullable();
            $table->string('dsc_esquema',100)->nullable();
            $table->string('dsc_restriccion_suelo',100)->nullable();
            $table->float('sup_ha',8,2)->nullable();
            $table->integer('cod_z_cpino')->nullable();
            $table->integer('cod_z_prod')->nullable();
            $table->integer('cod_sz_prod')->nullable();
            $table->text('dsc_sz_prod')->nullable();
            $table->integer('id_area_us')->nullable();
            $table->timestamps();
        });
rap2hpoutre commented 4 years ago

Hi @mojedar, thank you for your feedback, sorry for late answer!

What append if you try to run this query directly in your database (without using laravel)?

insert into "uso_suelo" ("cod_pais", "cod_fundo", "nom_fundo", "cod_uso_suelo", "dsc_uso_suelo", "cod_rodal", "cod_especie", "dsc_especie", "ano_plantacion", "cod_esquema", "dsc_esquema", "dsc_restriccion_suelo", "sup_ha", "cod_z_cpino", "cod_z_prod", "cod_sz_prod", "dsc_sz_prod", "id_area_us", "updated_at", "created_at") values (90, 5469, LOS QUILLAYES, 4050, CORTAFUEGO, , , , , , , SIN RESTRICCION, 0.2, 7, 4, 17, NAHUELBUTA INTERIOR ALTA, 32318, 2020-04-28 18:40:07, 2020-04-28 18:40:07) returning "id"

Do you see the same error?

mojedar commented 4 years ago

Hello !, oh, it has been so long that the truth I think that somehow I solved it at the time, so now I do not remember well how I solved it, Anyway thank you very much for answering, I love your library: D

El mié., 17 jun. 2020 a las 15:58, Raphaël Huchet (notifications@github.com) escribió:

Hi @mojedar https://github.com/mojedar, thank you for your feedback, sorry for late answer!

What append if you try to run this query directly in your database (without using laravel)?

insert into "uso_suelo" ("cod_pais", "cod_fundo", "nom_fundo", "cod_uso_suelo", "dsc_uso_suelo", "cod_rodal", "cod_especie", "dsc_especie", "ano_plantacion", "cod_esquema", "dsc_esquema", "dsc_restriccion_suelo", "sup_ha", "cod_z_cpino", "cod_z_prod", "cod_sz_prod", "dsc_sz_prod", "id_area_us", "updated_at", "created_at") values (90, 5469, LOS QUILLAYES, 4050, CORTAFUEGO, , , , , , , SIN RESTRICCION, 0.2, 7, 4, 17, NAHUELBUTA INTERIOR ALTA, 32318, 2020-04-28 18:40:07, 2020-04-28 18:40:07) returning "id"

Do you see the same error?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/rap2hpoutre/fast-excel/issues/167#issuecomment-645591333, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABZ6AXKERCEWMNDOT5LY4S3RXEN57ANCNFSM4MTH4QAQ .

-- María Paz Ojeda Rodríguez Egresada de Ingeniería Civil en Informática Universidad Austral de Chile