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

Error during the migration generation #29

Open
lavapi opened this issue Apr 14, 2020 · 9 comments
Open

Error during the migration generation #29

lavapi opened this issue Apr 14, 2020 · 9 comments

Comments

@lavapi
Copy link

lavapi commented Apr 14, 2020

I am getting an error when trying to generate migration from DB.

vendor\digitaldream\laracrud\src\lara-crud\Crud\MigrationCrud.php:222
218| * @throws \Exception
219| */
220| public function generateClassName($table)
221| {

222| $class = 'create' . ucfirst(camel_case($table)) . 'Table';
223|
224| if (class_exists($class)) {
225| throw new \Exception('Migration for table ' . $table . ' already exists');
226| }

Exception trace:

1 LaraCrud\Crud\MigrationCrud::generateClassName("users")
vendor\digitaldream\laracrud\src\lara-crud\Crud\MigrationCrud.php:94

2 LaraCrud\Crud\MigrationCrud::template()
vendor\digitaldream\laracrud\src\lara-crud\Crud\MigrationCrud.php:110

Please use the argument -v to see more details.

@lavapi
Copy link
Author

lavapi commented Apr 14, 2020

Can you just replace camel_case($table) with Str::camel($table)

@digitaldreams
Copy link
Owner

Thanks for letting me know.
Yes. i will definitely do that. I am working with V5 and its really cool. Until you have to wait.

@digitaldreams
Copy link
Owner

I hope you got the error. You already have a migration for your users table.
Try something else and it should create migration methods for you.

@lavapi
Copy link
Author

lavapi commented Apr 14, 2020

I fixed it temporarily but just informed you to fix it permanently :) P.S. perfect work...

@hardkraft
Copy link

Hi, in addition to this error I discovered that you don't handle the UNSIGNED attribute in MySQL 8.
The "unsigned" is returned with the column data type so it needs to be split first, otherwise the rules method won't match anything and returns nothing for the methodName which causes errors on line 71.
Also, it seems to me that you only consider int and bigint for primary keys. Is there a reason for that?

@hardkraft
Copy link

hardkraft commented Apr 28, 2020

I made some changes starting on line 127

`
$dataTypes = explode(' ',$column->type());
$dataType = $dataTypes[0];
$dataTypeAttr = !empty($dataTypes[1])? $dataTypes[1]:'';

        if ($column->isPk()) {
            if ($dataType == 'int') {
                $arr['methodName'] = 'increments';
            } elseif ($dataType == 'bigint') {
                $arr['methodName'] = 'bigIncrements';
            }
        } 
        if (empty($arr['methodName'])) {
            $arr['methodName'] = isset($this->columnMap[$dataType]) ? $this->columnMap[$dataType] : '';
        }`

I also added 'json' => 'json', to your $columnMap

Works well for my purposes but I didn't test it on anything else. Thanks for a great project :)

@digitaldreams
Copy link
Owner

@hardkraft thanks for code suggestion. I will definitely implement on next major version 5.0 which is under development now.

@nicholasbieber
Copy link

nicholasbieber commented Aug 13, 2021

I received this exact issue today in a fresh project, fresh "composer require digitaldream/laracrud --dev" - and line 222 had:
$class = 'create' . ucfirst(camel_case($table)) . 'Table';
instead of
$class = 'create'.Str::camel($table).'Table';
I swapped the lines out and it's fine now... I wish I could offer some insight but I'm a noob out of their depth. Probably something on this end.
Otherwise it all looks very spiffy!

@digitaldreams
Copy link
Owner

Hi @nicholasbieber
This issue is fixed on dev-master. You can use this version. The next Major version 5 is expected to be release in October this year.

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

No branches or pull requests

3 participants