我正在尝试开始使用CakePHP模式:app/Console/cake schema generate
我收到以下错误:

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.

这是令人困惑的,因为该站点运行良好,因此Config/database.php中的DB凭据是正确的。

更新:
因为我使用的是MAMP,所以将以下内容添加到$ defualt数组中的Config/database.php中:
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',

现在我没有原始错误,而是一些新错误:
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}

看起来CakePHP吓坏了ENUM字段。

最佳答案

正如在这里非常明确地描述的那样...

Cakephp + enum support : unable to save or select enum 0 and 1

... CakePHP不喜欢ENUM字段。似乎与模式相关的控制台工具将在那里使用。

关于php - CakePHP:尝试生成模式时出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19794484/

10-16 14:48