当my bin/cake bake all
命令工作时,我打印了所有可能的模型名称,基于我的数据库进行烘焙,我的迁移工作无效。这是我得到它的错误。
bin/cake migrations seed
Welcome to CakePHP v3.3.12 Console
---------------------------------------------------------------
App : src
Path: /Users/myhostcomputer/workspace/myapp/src/
PHP : 7.1.0
---------------------------------------------------------------
Exception: Could not infer database type from driver in [/Users/myhostcomputer/workspace/myapp/vendor/cakephp/migrations/src/ConfigurationTrait.php, line 151]
2017-01-28 12:47:48 Error: [InvalidArgumentException] Could not infer database type from driver
Stack Trace:
#0 /Users/myhostcomputer/workspace/myapp/vendor/cakephp/migrations/src/ConfigurationTrait.php(83): Migrations\Command\Seed->getAdapterName('mysql')
#1 /Users/myhostcomputer/workspace/myapp/vendor/robmorgan/phinx/src/Phinx/Console/Command/AbstractCommand.php(91): Migrations\Command\Seed->getConfig()
#2 /Users/myhostcomputer/workspace/myapp/vendor/cakephp/migrations/src/ConfigurationTrait.php(206): Phinx\Console\Command\AbstractCommand->bootstrap(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 /Users/myhostcomputer/workspace/myapp/vendor/cakephp/migrations/src/Command/Seed.php(69): Migrations\Command\Seed->bootstrap(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 /Users/myhostcomputer/workspace/myapp/vendor/symfony/console/Command/Command.php(262): Migrations\Command\Seed->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#5 /Users/myhostcomputer/workspace/myapp/vendor/symfony/console/Application.php(826): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#6 /Users/myhostcomputer/workspace/myapp/vendor/symfony/console/Application.php(189): Symfony\Component\Console\Application->doRunCommand(Object(Migrations\Command\Seed), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#7 /Users/myhostcomputer/workspace/myapp/vendor/symfony/console/Application.php(120): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#8 /Users/myhostcomputer/workspace/myapp/vendor/cakephp/migrations/src/Shell/MigrationsShell.php(101): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#9 [internal function]: Migrations\Shell\MigrationsShell->main('migrations', 'seed')
#10 /Users/myhostcomputer/workspace/myapp/vendor/cakephp/cakephp/src/Console/Shell.php(472): call_user_func_array(Array, Array)
#11 /Users/myhostcomputer/workspace/myapp/vendor/cakephp/migrations/src/Shell/MigrationsShell.php(156): Cake\Console\Shell->runCommand(Array, true, Array)
#12 /Users/myhostcomputer/workspace/myapp/vendor/cakephp/cakephp/src/Console/ShellDispatcher.php(227): Migrations\Shell\MigrationsShell->runCommand(Array, true, Array)
#13 /Users/myhostcomputer/workspace/myapp/vendor/cakephp/cakephp/src/Console/ShellDispatcher.php(182): Cake\Console\ShellDispatcher->_dispatch(Array)
#14 /Users/myhostcomputer/workspace/myapp/vendor/cakephp/cakephp/src/Console/ShellDispatcher.php(128): Cake\Console\ShellDispatcher->dispatch(Array)
#15 /Users/myhostcomputer/workspace/myapp/bin/cake.php(34): Cake\Console\ShellDispatcher::run(Array)
#16 {main}
这是我在app.php
中的数据源配置'Datasources' => [
'default' => [
'className' => 'Cake\Database\Connection',
'driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'port' => '/Applications/MAMP/tmp/mysql/mysql.sock',
'username' => 'XXXXXXXX',
'password' => 'XXXXXXXXXXXXXXXX',
'database' => 'XXXXXXXX',
'encoding' => 'utf8',
'timezone' => 'UTC',
'flags' => [],
'cacheMetadata' => true,
'log' => false,
'quoteIdentifiers' => false,
//'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'],
'url' => env('DATABASE_URL', null),
],
也许它必须对我在mac os上工作以及我使用MAMP做些什么
答案 0 :(得分:1)
mysql
不是有效的driver
选项值,这很可能会在区分大小写的文件系统上失败,因为它会转换为名为mysql.php
的文件。
正确的短类名是Mysql
,大写M
,但是迁移插件不支持短类名(可以在the source where the exception is being thrown中看到),它要么是(完全)限定的类名,或构造的驱动程序类实例。
所以,长话短说:
'driver' => \Cake\Database\Driver\Mysql::class