我将带有高级应用程序模板的Yii 2安装到我的localhost一切都很好,除了命令迁移我使用cmd创建用户表时它没有做任何事情。我在main-local中的代码:“I:\ zzerver \ Uwamp -port 84 \ uw-cms-p8585 \ www \ yii1 \ common \ config \ main-local.php”
是:
return [
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost:8585;dbname=db001name001',
'username' => 'db001user001',
'password' => 'yii2db001',
'charset' => 'utf8',
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@common/mail',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => true,
],
],
];
我确实将localhost:8585更改为127.0.0.1:8585,但仍然有同样的问题,我使用phpmyadmin,服务器是Uwamp
init命令工作正常,但是当我尝试:php yii migrate或yii migrate没有发生任何事情。这是cmd
它显示的所有内容,以及数据库中没有创建的内容
我确实下载了“Yii 2 with advanced application template”,之后我打开了cmd并运行了php init
I:\zzerver\Uwamp -port 84\uw-cms-p8585\www\yii1>php init
Yii Application Initialization Tool v1.0
Which environment do you want the application to be initialized in?
[0] Development
[1] Production
Your choice [0-1, or "q" to quit] 0
Initialize the application under 'Development' environment? [yes|no] y
Start initialization ...
exist backend/config/main-local.php
...overwrite? [Yes|No|All|Quit] All
overwrite backend/config/main-local.php
unchanged backend/config/params-local.php
unchanged backend/config/test-local.php
unchanged backend/web/index-test.php
unchanged backend/web/index.php
unchanged backend/web/robots.txt
overwrite common/config/main-local.php
unchanged common/config/params-local.php
unchanged common/config/test-local.php
unchanged console/config/main-local.php
unchanged console/config/params-local.php
overwrite frontend/config/main-local.php
unchanged frontend/config/params-local.php
unchanged frontend/config/test-local.php
unchanged frontend/web/index-test.php
unchanged frontend/web/index.php
unchanged frontend/web/robots.txt
unchanged yii
unchanged yii_test
unchanged yii_test.bat
generate cookie validation key in backend/config/main-local.php
generate cookie validation key in frontend/config/main-local.php
chmod 0777 backend/runtime
chmod 0777 backend/web/assets
chmod 0777 frontend/runtime
chmod 0777 frontend/web/assets
chmod 0755 yii
chmod 0755 yii_test
... initialization completed.
I:\zzerver\Uwamp -port 84\uw-cms-p8585\www\yii1>
我创建了数据库名称:db001name001,user:db001name001,password:yii2db001,
我向common \ config \ main-local.php添加信息
我再次打开cmd并运行php yii migrate
I:\zzerver\Uwamp -port 84\uw-cms-p8585\www\yii1>php yii migrate
Yii Migration Tool (based on Yii v2.0.13-dev)
但是没有任何事情没有为用户创建表,我想为用户创建表以开始创建注册表单
COMMON \设置\主local.php
<?php
return [
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost:8585;dbname=db001name001',
'username' => 'db001user001',
'password' => 'yii2db001',
'charset' => 'utf8',
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@common/mail',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => true,
],
],
];
COMMON \设置\ main.php:
<?php
return [
'aliases' => [
'@bower' => '@vendor/bower-asset',
'@npm' => '@vendor/npm-asset',
],
'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
'components' => [
'cache' => [
'class' => 'yii\caching\FileCache',
],
],
];
我的控制台控制台\ config \ main.php“
<?php
$params = array_merge(
require __DIR__ . '/../../common/config/params.php',
require __DIR__ . '/../../common/config/params-local.php',
require __DIR__ . '/params.php',
require __DIR__ . '/params-local.php'
);
return [
'id' => 'app-console',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'controllerNamespace' => 'console\controllers',
'aliases' => [
'@bower' => '@vendor/bower-asset',
'@npm' => '@vendor/npm-asset',
],
'controllerMap' => [
'fixture' => [
'class' => 'yii\console\controllers\FixtureController',
'namespace' => 'common\fixtures',
],
],
'components' => [
'log' => [
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
],
'params' => $params,
];
仅根据您提供的信息,我建议您阅读有关Yii2迁移here的信息。在您的示例中,您没有向Yii提供任何命令,只检查是否安装了迁移工具。之后/如果您已经这样做了,请澄清您的问题 - 向我们展示您尝试运行的命令,以及错误消息,如果有的话。
链接的文档有一些示例,包括用于创建表的代码,您想要执行的操作。
在第一眼看来,您的控制台/ config / main.php中没有数据库组件设置
尝试添加适当的数据库连接,例如mysql
<?php
$params = array_merge(
require(__DIR__ . '/../../common/config/params.php'),
require(__DIR__ . '/../../common/config/params-local.php'),
require(__DIR__ . '/params.php'),
require(__DIR__ . '/params-local.php')
);
return [
'id' => 'app-console',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'controllerNamespace' => 'console\controllers',
'components' => [
'log' => [
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=my_db_name',
'username' => 'my_root',
'password' => 'my_pwd',
'charset' => 'utf8',
'enableSchemaCache' => true,
],
],
'params' => $params,
];
然后尝试运行迁移命令