Reputation: 705
I installed Yii 2 with advanced application template to my localhost everything is fine except command migrate when I use cmd to create user table it doesn't do any thing. My code in main-local : "I:\zzerver\Uwamp -port 84\uw-cms-p8585\www\yii1\common\config\main-local.php"
is :
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,
],
],
];
I did change localhost:8585 to 127.0.0.1:8585 but still has the same problem, I'm using phpmyadmin, and server is Uwamp
the init command work good but when I try : php yii migrate or yii migrate no thing happen. this is the cmd
that all what it show , and nothing created in database
I did download "Yii 2 with advanced application template" after that I did open cmd and run 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>
I created database name : db001name001, user : db001name001, password : yii2db001,
I add information to common\config\main-local.php
I did open again cmd and run 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)
but nothing happen no table created for user, I want to create table for user to start creating a signup form
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,
],
],
];
common\config\main.php:
<?php
return [
'aliases' => [
'@bower' => '@vendor/bower-asset',
'@npm' => '@vendor/npm-asset',
],
'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
'components' => [
'cache' => [
'class' => 'yii\caching\FileCache',
],
],
];
my console 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,
];
Upvotes: 0
Views: 9587
Reputation: 133400
at the first look ssems you have not db component seeting in your console/config/main.php
try add a proper db connect eg for 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,
];
and then try run you migration command
Upvotes: 0
Reputation: 592
Going by only the information you provided, I'd suggest that you read about Yii2 migrations here. In your example you did not provide any commands to Yii, just checked if the migration tool is installed. After/If you've done that, please, clarify your question - show us what commands you've tried to run, and the error messages too, if there's any.
The linked documentation has a few examples, including code for creating tables, the same thing you want to do.
Upvotes: 0