[英]Yii2 create user table
我将带有高级应用程序模板的 Yii 2 安装到我的本地主机上,一切都很好,除了命令 migrate 当我使用 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 没有任何反应。 这是命令
它显示的所有内容,并且没有在数据库中创建任何内容
我确实下载了“带有高级应用程序模板的 Yii 2”,然后我打开了 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,用户:db001name001,密码: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\config\main-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,
],
],
];
常见\配置\main.php:
<?php
return [
'aliases' => [
'@bower' => '@vendor/bower-asset',
'@npm' => '@vendor/npm-asset',
],
'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
'components' => [
'cache' => [
'class' => 'yii\caching\FileCache',
],
],
];
我的控制台 console\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 迁移的信息。 在您的示例中,您没有向 Yii 提供任何命令,只是检查了是否安装了迁移工具。 之后/如果您这样做了,请澄清您的问题 - 向我们展示您尝试运行的命令,以及错误消息(如果有)。
链接的文档有一些示例,包括用于创建表的代码,这与您想要做的事情相同。
乍一看 ssems,你的 console/config/main.php 中没有 db 组件
尝试添加适当的数据库连接,例如为 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,
];
然后尝试运行你的迁移命令
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.