XCMer / larry-four-generator

Larry Laravel Generator For Laravel Four
Other
131 stars 27 forks source link

Larry Migration and Autoloading Issue with table names containing underscores #7

Open dannysuryadi opened 11 years ago

dannysuryadi commented 11 years ago

I dunno if this is a laravel or larry-related issue, but when I created tables with underscores as its table name and then ran "php artisan dump-autoload" on the CLI, it creates unrecognized class name for the migration class and autoload_classmap.php, making it unable to be reset/rollback/refreshed. Example:

Larry file: User myproject_user id increments name string

It creates a migration class with class name CreateMyprojectuserTable

It runs fine when I run "php artisan migrate" but when I run "php artisan migrate:reset", it shows an error with the message "class CreateMyprojectUserTable not found". The only workaround I've found so far is to manually change the generated migration class name from CreateMyprojectuserTable to CreateMyprojectUserTable (notice the capital U), as well as the class name in the autoload_classmap.php file.

I hope this issue can be fixed in the next release. I'm still new to this laravel stuff and larry helps a lot in creating migrations and models. Thanks a bunch!

Gadoma commented 11 years ago

I had some issues with the migrate:reset as well - and it seems similar to the above of @kamuikurou. Im not sure if it was identical and have no option to replicate the error though.

I just stopped using migration reset at that moment and wrote myself a custom bash script to handle the needed db maintenance routines.

If your "myproject" is a tablename prefix and all you tables begin with it, just set it in /app/config/app.php and remove from tablename in larry file - it might solve your problem temporarily as you will have table names made just form one word ;)

dannysuryadi commented 11 years ago

Nice, thanks for the tip! :D I can't find any place to put the table name prefix in /app/config/app.php but I put it in /app/config/database.php. I still have to rename the migration classes of some of my tables with underscores like transaction_headers and transaction_details though.

Oh, and I found that I only have to rename the class names in the generated migration files before doing dump-autoload so I don't have to open autoload_classmap.php and change the class names in there also.

Gadoma commented 11 years ago

ofcourse you are right - I thought about the database.php but just automaticaly wrote app.php - my bad :)

XCMer commented 11 years ago

I tried creating an underscored table with laravel's own migration generator, and ran into issues while rolling back. Even though the class was named properly, it was still not found by Laravel. Is this a glitch in my installation?

Also, I've written the corrected code so that the migration file name is properly cased. However, I am not able to test it at the moment, which is why I'm waiting to push the change.

Gadoma commented 11 years ago

@XCMer I think that we came across the same issue which seems to be a Laravel problem, rather than Larry. But as I wrote, I didn't investigate that further, just did what I needed at that time with a little hack (by using an external shell script) :)

LarryEitel commented 10 years ago

Just to clarify how I worked around this.

Previously, if I ran php artisan migrate:reset, it failed with:

PHP Fatal error:  Class '_____' not found in /home/vagrant/Code/nbhome/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php on line 297

Per another discussion on the subject I learned that running composer dump-autoload resolves this.

Now I can successfully run php artisan migrate:reset.