I'm trying to start using CakePHP schema: app/Console/cake schema generate
I get the following error:
Welcome to CakePHP v2.3.0 Console
---------------------------------------------------------------
App : app
Path: /Applications/MAMP/htdocs/mysite/app/
---------------------------------------------------------------
Cake Schema Shell
---------------------------------------------------------------
Error: Database connection "Mysql" is missing, or could not be created.
This is confusing because the site is running fine, so the DB credentials in Config/database.php are correct.
Update: Because I'm using MAMP, I added the following to my Config/database.php in the $defualt array:
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
Now I don't get the original error, but rather some new ones:
Welcome to CakePHP v2.3.0 Console
---------------------------------------------------------------
App : app
Path: /Applications/MAMP/htdocs/mysite/app/
---------------------------------------------------------------
Cake Schema Shell
---------------------------------------------------------------
Generating Schema...
Notice Error: Schema generation error: invalid column type enum('normal','unlimited_time','admin','extra_time') for Attempt.type does not exist in DBO in [/Applications/MAMP/htdocs/mysite/lib/Cake/Model/CakeSchema.php, line 616]
Notice Error: Schema generation error: invalid column type enum('in_progress','complete','canceled') for Attempt.status does not exist in DBO in [/Applications/MAMP/htdocs/mysite/lib/Cake/Model/CakeSchema.php, line 616]
Notice Error: Schema generation error: invalid column type enum('MC','FI','CS','CQ','TF') for AttemptedQuestion.type does not exist in DBO in [/Applications/MAMP/htdocs/mysite/lib/Cake/Model/CakeSchema.php, line 616]
Notice Error: Schema generation error: invalid column type enum('1','2','3') for Category.category_order does not exist in DBO in [/Applications/MAMP/htdocs/mysite/lib/Cake/Model/CakeSchema.php, line 616]
Error: Table choices for model Choice was not found in datasource default.
#0 /Applications/MAMP/htdocs/mysite/lib/Cake/Model/Model.php(3217): Model->setSource('choices')
#1 /Applications/MAMP/htdocs/mysite/lib/Cake/Model/CakeSchema.php(260): Model->getDataSource()
#2 /Applications/MAMP/htdocs/mysite/lib/Cake/Console/Command/SchemaShell.php(149): CakeSchema->read(Array)
#3 /Applications/MAMP/htdocs/mysite/lib/Cake/Console/Shell.php(388): SchemaShell->generate()
#4 /Applications/MAMP/htdocs/mysite/lib/Cake/Console/ShellDispatcher.php(199): Shell->runCommand('generate', Array)
#5 /Applications/MAMP/htdocs/mysite/lib/Cake/Console/ShellDispatcher.php(67): ShellDispatcher->dispatch()
#6 /Applications/MAMP/htdocs/mysite/app/Console/cake.php(33): ShellDispatcher::run(Array)
#7 {main}
Looks like CakePHP is freaking out about the ENUM fields.
As described pretty definitively here...
Cakephp + enum support : unable to save or select enum 0 and 1
...CakePHP does not like ENUM fields. It looks like the Console tools related to the schema are going to work with them there.
Old question, I know. But I just fixed this issue yesterday while working in a really old project of mine.
If you still need this kind of solution, I posted on this git public repository.
https://github.com/matheuscmpm/cakephp-schema-enum
You basicly need to alter the Datasource/Database/Mysql.php file to insert the ENUM as an accepted type and them alter the Model/CakeSchema.php to handle them.
If you don't want to alter your cakephp 2.x files, you can copy them to your project app folder, just like I did. In this README.md file, you can see what exactly I changed in this both files, you can replicate the same solution to handle SET type fields as well.
I just did that to work with MySQL, so with you need to another database, you will also need to change a couple things in others datasource/database files.
Cheers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With