Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot run command to create flat table #24

Open
joaopmmartins opened this issue Dec 10, 2018 · 9 comments
Open

Cannot run command to create flat table #24

joaopmmartins opened this issue Dec 10, 2018 · 9 comments

Comments

@joaopmmartins
Copy link

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.

@sunel
Copy link
Owner

sunel commented Dec 11, 2018

@joaopmmartins

What version of php and laravel are you using .

@sunel
Copy link
Owner

sunel commented Dec 11, 2018

@joaopmmartins

Try running now

@joaopmmartins
Copy link
Author

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'); } }

@sunel
Copy link
Owner

sunel commented Dec 18, 2018

@joaopmmartins

Can you check if you have the latest code.

@joaopmmartins
Copy link
Author

joaopmmartins commented Jan 8, 2019

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

@sunel
Copy link
Owner

sunel commented Jan 9, 2019

@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

@joaopmmartins
Copy link
Author

joaopmmartins commented Jan 9, 2019

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?

@sunel
Copy link
Owner

sunel commented Jan 10, 2019

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

@sunel sunel added MS_SQL and removed in-review labels Jan 17, 2019
@leduyhoang1994
Copy link

leduyhoang1994 commented Jun 8, 2020

@sunel hey, i found this error ocured when i added no attributes to the entity. I use only static attributes for initial.
This line

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

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 !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants