[英]CakePHP: Error trying to generate a schema
I'm trying to start using CakePHP schema: app/Console/cake schema generate
我正在尝试开始使用CakePHP架构: 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. 这很令人困惑,因为站点运行正常,因此Config / database.php中的DB凭据是正确的。
Update: Because I'm using MAMP, I added the following to my Config/database.php in the $defualt array: 更新:因为我正在使用MAMP,所以我在$ defualt数组中的Config / database.php中添加了以下内容:
'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. 看起来像CakePHP对ENUM领域感到害怕。
As described pretty definitively here... 正如这里所描述的那样明确......
Cakephp + enum support : unable to save or select enum 0 and 1 Cakephp + enum支持:无法保存或选择枚举0和1
...CakePHP does not like ENUM fields. ... CakePHP不喜欢ENUM字段。 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. 如果你仍然需要这种解决方案,我发布在这个git公共存储库上。
https://github.com/matheuscmpm/cakephp-schema-enum 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. 您基本上需要更改Datasource / Database / Mysql.php文件以将ENUM作为接受类型插入,并且它们会更改Model / CakeSchema.php来处理它们。
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. 如果您不想更改cakephp 2.x文件,可以将它们复制到项目应用程序文件夹中,就像我一样。 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. 在这个README.md文件中,您可以看到我在这两个文件中确切改变了什么,您也可以复制相同的解决方案来处理SET类型字段。
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. 我只是这样做与MySQL合作,所以你需要另一个数据库,你还需要在其他数据源/数据库文件中更改一些东西。
Cheers. 干杯。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.