夹具"用户"在MySQL中加载但未在MS SQL Server中加载

时间:2016-06-13 05:44:13

标签: mysql sql-server yii2 fixtures codeception

我安装了高级应用程序模板,创建了两个数据库yii2advanced:一个在本地MySQL中另一个在远程MS SQL Server中:

'components' => [
    'db' => [
        'class' => '\yii\db\Connection',
        'dsn' => 'mysql:host=127.0.0.1;dbname=yii2advanced',
        'username' => 'root',
        'password' => 'root',
//    'dsn' => 'sqlsrv:Server=..;Database=yii2advanced;MultipleActiveResultSets=false',
//    'username' => 'sa',
//    'password' => 'sa',
        'charset' => 'utf8',
        'tablePrefix' => 'tbl_',
    ],
],

在两个数据库上应用迁移:

yii migrate

现在两个数据库都有名为tbl_usertbl_migration的表。

MS SQL Server的

CREATE TABLE语句:

CREATE TABLE [dbo].[tbl_user](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [username] [nvarchar](255) NOT NULL,
    [auth_key] [nvarchar](32) NOT NULL,
    [password_hash] [nvarchar](255) NOT NULL,
    [password_reset_token] [nvarchar](255) NULL,
    [email] [nvarchar](255) NOT NULL,
    [status] [smallint] NOT NULL,
    [created_at] [int] NOT NULL,
    [updated_at] [int] NOT NULL,
PRIMARY KEY CLUSTERED 
(
    [id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
UNIQUE NONCLUSTERED 
(
    [password_reset_token] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
UNIQUE NONCLUSTERED 
(
    [email] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
UNIQUE NONCLUSTERED 
(
    [username] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
MySQL的

CREATE TABLE声明:

CREATE TABLE `tbl_user` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `username` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
 `auth_key` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
 `password_hash` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
 `password_reset_token` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
 `email` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
 `status` smallint(6) NOT NULL DEFAULT '10',
 `created_at` int(11) NOT NULL,
 `updated_at` int(11) NOT NULL,
 PRIMARY KEY (`id`),
 UNIQUE KEY `username` (`username`),
 UNIQUE KEY `email` (`email`),
 UNIQUE KEY `password_reset_token` (`password_reset_token`)
 ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci

接下来,我将fixture装入MySQL表tbl_user

C:\php-projects\advanced\tests\codeception\bin>yii fixture/load User
Fixtures namespace is:
        tests\codeception\common\fixtures

Global fixtures will be used:

        1. yii\test\InitDb

Fixtures below will be loaded:

        1. User

Be aware that:
Applying leads to purging of certain data in the database!

Load above fixtures? (yes|no) [no]:yes

Fixtures were successfully loaded from namespace:
        "tests\codeception\common\fixtures"

        1. yii\test\InitDbFixture
        2. tests\codeception\common\fixtures\UserFixture

尝试将夹具加载到MS SQL Server的表[dbo].[tbl_user]中,但获得异常:

C:\php-projects\advanced\tests\codeception\bin>yii fixture/load User
Fixtures namespace is:
        tests\codeception\common\fixtures

Global fixtures will be used:

        1. yii\test\InitDb

Fixtures below will be loaded:

        1. User

Be aware that:
Applying leads to purging of certain data in the database!

Load above fixtures? (yes|no) [no]:yes

Exception 'yii\base\InvalidParamException' with message 'Table not found: []'

in C:\php-projects\advanced\vendor\yiisoft\yii2\db\mssql\QueryBuilder.php:182

Stack trace:
0 C:\php-projects\advanced\vendor\yiisoft\yii2\db\Command.php(754): yii\db\mssql\QueryBuilder->checkIntegrity(false, '', '')
1 C:\php-projects\advanced\vendor\yiisoft\yii2\test\InitDbFixture.php(94): yii\db\Command->checkIntegrity(false, '')
2 C:\php-projects\advanced\vendor\yiisoft\yii2\test\InitDbFixture.php(76): yii\test\InitDbFixture->checkIntegrity(false)
3 C:\php-projects\advanced\vendor\yiisoft\yii2\test\FixtureTrait.php(114): yii\test\InitDbFixture->beforeUnload()
4 C:\php-projects\advanced\vendor\yiisoft\yii2\console\controllers\FixtureController.php(159): yii\console\controllers\FixtureController->unloadFixtures(Array)

5 [internal function]: yii\console\controllers\FixtureController->actionLoad('User')
6 C:\php-projects\advanced\vendor\yiisoft\yii2\base\InlineAction.php(55): call_user_func_array(Array, Array)
7 C:\php-projects\advanced\vendor\yiisoft\yii2\base\Controller.php(154): yii\base\InlineAction->runWithParams(Array)
8 C:\php-projects\advanced\vendor\yiisoft\yii2\console\Controller.php(119): yii\base\Controller->runAction('load', Array)
9 C:\php-projects\advanced\vendor\yiisoft\yii2\base\Module.php(454): yii\console\Controller->runAction('load', Array)
10 C:\php-projects\advanced\vendor\yiisoft\yii2\console\Application.php(176): yii\base\Module->runAction('fixture/load', Array)
11 C:\php-projects\advanced\vendor\yiisoft\yii2\console\Application.php(143): yii\console\Application->runAction('fixture/load', Array)
12 C:\php-projects\advanced\vendor\yiisoft\yii2\base\Application.php(375): yii\console\Application->handleRequest(Object(yii\console\Request))
13 C:\php-projects\advanced\tests\codeception\bin\yii(23): yii\base\Application->run()
14 {main}

为什么User fixture没有加载到MS SQL Server中的表中?也许原因在于[dbo]计划?

[更新]

尝试按如下所述定义表名,有几个变体,但都没有帮助:

public static function tableName()
{
    return 'dbo..tbl_user'
}
...
public static function tableName()
{
    return 'dbo.sa.tbl_user'
}
...
public static function tableName()
{
    return '{{dbo.sa.%user}}'
}
...

..等等。可能是什么原因?我非常感谢这些信息。谢谢大家。

0 个答案:

没有答案