[英]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.