eav icon indicating copy to clipboard operation
eav copied to clipboard

Cannot run command to create flat table

Open joaopmmartins opened this issue 6 years ago • 9 comments

When I run the command 'php artisan eav:compile:entity product' to create the flat table I get the following error:

Compiling product entity. Creating flat table for products. in C:\Websites\eavproject\database/migrations/eav/products_flat.php Found 14 attributes.

In products_flat.php line 18:

syntax error, unexpected '(', expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$'

And it creates the products_flat.php with the following syntax errors:

.... .... public function up() { Schema::dropIfExists('products_flat'); Schema::create('products_flat', function (Blueprint $table) { $table->(''); $table->string()('accessible_furniture_shape')->nullable(); $table->string()('item_weight_kg')->nullable(); $table->string()('strength_options')->nullable(); $table->string()('size')->nullable()->default('s'); $table->string()('length')->nullable(); $table->string()('width')->nullable(); $table->string()('item_weight_g')->nullable(); $table->int('featured_product')->nullable(); $table->string()('garden_tool_type')->nullable(); $table->string()('accessible_furniture_material')->nullable(); $table->int('garden_stool_arms')->nullable(); $table->string()('color_options')->nullable(); $table->string()('garden_tools_material')->nullable(); $table->string()('weight')->nullable(); }); }

.....

Any idea why is this happening? Thanks.

joaopmmartins avatar Dec 10 '18 00:12 joaopmmartins

@joaopmmartins

What version of php and laravel are you using .

sunel avatar Dec 11 '18 02:12 sunel

@joaopmmartins

Try running now

sunel avatar Dec 11 '18 16:12 sunel

I still get the same error. I am using laravel 5.7.14 and PHP 7.2.4. I have the following attributes in the SQL Server (not mysql) database:

accessible_furniture_shape item_weight_kg strength_options size length width item_weight_g featured_product garden_tool_type garden_stool_arms color_options garden_tools_material weight tags

when i run the query php artisan eav:compile:entity product, it creates a class with syntax errors. It adds $table->(''); and $table->string(),...

(''); $table->string()('accessible_furniture_shape')->nullable(); $table->string()('item_weight_kg')->nullable(); $table->string()('strength_options')->nullable(); $table->string()('size')->nullable()->default('s'); $table->string()('length')->nullable(); $table->string()('width')->nullable(); $table->string()('item_weight_g')->nullable(); $table->int('featured_product')->nullable(); $table->string()('garden_tool_type')->nullable(); $table->int('garden_stool_arms')->nullable(); $table->string()('color_options')->nullable(); $table->string()('garden_tools_material')->nullable(); $table->string()('weight')->nullable(); $table->string()('tags')->nullable(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::drop('product_flat'); } }

joaopmmartins avatar Dec 17 '18 12:12 joaopmmartins

@joaopmmartins

Can you check if you have the latest code.

sunel avatar Dec 18 '18 17:12 sunel

Hi sunel , Happy new Year!

Yes, I've updated the code but I am still having problems creating the 'product_flat' migration file. I am using a MS_SQL Database.

When I run the command "php artisan eav:compile:entity product"

it creates a migration file with errors. See the screenshot below.

In addition to all the attributes columns, can you please tell me what other columns should exist in the flat table so I can create them manually? Many thanks.

The migration file created:

image

The attributes table:

image

The entities table:

image

joaopmmartins avatar Jan 08 '19 20:01 joaopmmartins

@joaopmmartins

Ok so this issue is in MS SQL.

I have never tested this package in MS SQL. I will try to test it.

Mean while here what the up migration for flat table looks like in MYSQL

/**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::dropIfExists('products_flat');
		Schema::create('products_flat', function (Blueprint $table) {
            $table->integer('id')->unsigned();
            $table->integer('entity_id')->unsigned();
            $table->integer('attribute_set_id')->unsigned();
            $table->timestamp('created_at')->nullable();
            $table->timestamp('updated_at')->nullable();
            $table->string('sku', 191)->nullable();
            $table->string('name', 191)->nullable();
            $table->boolean('search')->nullable();
            $table->text('description')->nullable();
            $table->point('location')->nullable();
            $table->dateTimeTz('located_at')->nullable();
        });
    }

Here is where this needs to be fixed.

https://github.com/sunel/eav/blob/51d64040a074fb5dec5c2ebb2b714901a9daef0d/src/Flat/Entity/Complier.php#L85_L161

Let me know if where able to find the issue

I presume the information_schema has different result.

https://github.com/sunel/eav/blob/51d64040a074fb5dec5c2ebb2b714901a9daef0d/src/Flat/Entity/Complier.php#L182_L186

sunel avatar Jan 09 '19 15:01 sunel

It gave me error :(:)

SQLSTATE[IMSSP]: Tried to bind parameter number 2101. SQL Server supports a maximum of 2100 parameters.

I have additional columns in my product table (not in the eav tables), including name, description, metakeywords, ... I defined those attribute as 'backend_type' => 'static' in the attributes table. Do I have to create the same columns in the flat table as well?

joaopmmartins avatar Jan 09 '19 23:01 joaopmmartins

Yes, Flat table are normalized form of all the tables.

sunel avatar Jan 10 '19 04:01 sunel

@sunel hey, i found this error ocured when i added no attributes to the entity. I use only static attributes for initial. This line https://github.com/sunel/eav/blob/51d64040a074fb5dec5c2ebb2b714901a9daef0d/src/Flat/Entity/Complier.php#L158 Please update it like "if there are no attributes then adding no "," after the schema".

$schema = (new SchemaParser)->parse($table->implode(',').(count($attributes) > 0 ? ',' : '').$attributes->implode(','));

Thanks !!

leduyhoang1994 avatar Jun 08 '20 04:06 leduyhoang1994