Php Yii迁移,不创建表
我是Yii(仍在学习)的新手,我正在学习一本书的教程 在这里,我按照书中写的那样创建了一个新的迁移Php Yii迁移,不创建表,php,yii,Php,Yii,我是Yii(仍在学习)的新手,我正在学习一本书的教程 在这里,我按照书中写的那样创建了一个新的迁移 yiic migrate create create_issue_user_and_assignment_tables 在safeup中我写了这个查询 $this->createTable('tbl_issue', array( 'id' => 'pk', 'name' => 'string NOT NULL', 'description' => 'text', 'pro
yiic migrate create create_issue_user_and_assignment_tables
在safeup中我写了这个查询
$this->createTable('tbl_issue', array(
'id' => 'pk',
'name' => 'string NOT NULL',
'description' => 'text',
'project_id' => 'int(11) DEFAULT NULL',
'type_id' => 'int(11) DEFAULT NULL',
'status_id' => 'int(11) DEFAULT NULL',
'owner_id' => 'int(11) DEFAULT NULL',
'requester_id' => 'int(11) DEFAULT NULL',
'create_time' => 'datetime DEFAULT NULL',
'create_user_id' => 'int(11) DEFAULT NULL',
'update_time' => 'datetime DEFAULT NULL',
'update_user_id' => 'int(11) DEFAULT NULL',
), 'ENGINE=InnoDB');
//create the user table
$this->createTable('tbl_user', array(
'id' => 'pk',
'username' => 'string NOT NULL',
'email' => 'string NOT NULL',
'password' => 'string NOT NULL',
'last_login_time' => 'datetime DEFAULT NULL',
'create_time' => 'datetime DEFAULT NULL',
'create_user_id' => 'int(11) DEFAULT NULL',
'update_time' => 'datetime DEFAULT NULL',
'update_user_id' => 'int(11) DEFAULT NULL',
), 'ENGINE=InnoDB');
而这个在safeDown()中
然后运行它并得到以下消息
D:\wamp\www\yiisite\protected>yiic migrate
PHP Deprecated: Directive 'register_globals' is deprecated in PHP 5.3 and great
er in Unknown on line 0
Deprecated: Directive 'register_globals' is deprecated in PHP 5.3 and greater in
Unknown on line 0
Yii Migration Tool v1.0 (based on Yii v1.1.13)
Total 1 new migration to be applied:
m130703_085302_create_issue_user_and_assignment_tables
Apply the above migration? (yes|no) [no]:yes
*** applying m130703_085302_create_issue_user_and_assignment_tables
*** applied m130703_085302_create_issue_user_and_assignment_tables (time: 0.042s
)
Migrated up successfully.
现在的问题是没有在数据库中创建表,这可能是因为不推荐使用register\u globals的消息,但我不确定该怎么办,连接参数是否正确,并且在表tbl\u中插入了一条记录
m130703_085302_create_issue_user_and_assignment_ta... 1372842220
但是没有创建新的表。我只是干运行了您在其中创建表的代码,所以我必须假设您的调用有问题。唯一能立即指出的是,您运行的是bash脚本,而不是bat脚本 yiic是一个bash脚本。在Windows上,建议运行yiic.bat或yiic.php 可以从命令行运行php吗?如果是:
- 从tbl_迁移中删除迁移
- 以“C:\path\to\php.exe yiic.php migrate up”的形式运行迁移
- 从tbl_迁移中删除迁移
- 以“C:\path\to\php.exe yiic.php migrate up”的形式运行迁移
<?php
class m130630_124600_some_description_name extends CDbMigration
{
public function up(){
//upcode example create the session table
$this->createTable('session',[
'id' => "varchar(40) NOT NULL",
'expire' => "int(12)",
'data' => "blob",
]);
$this->addPrimaryKey('idx','session','id');
}
public function down(){
// downcode (undo the up code) example: drop session table
$this->dropTable('session');
}
}
创建表通常不需要事务处理
<?php
class m130630_124600_some_description_name extends CDbMigration
{
public function up(){
//upcode example create the session table
$this->createTable('session',[
'id' => "varchar(40) NOT NULL",
'expire' => "int(12)",
'data' => "blob",
]);
$this->addPrimaryKey('idx','session','id');
}
public function down(){
// downcode (undo the up code) example: drop session table
$this->dropTable('session');
}
}
检查config/console.php文件 更改数据库名、用户名和密码。 这是yiic命令使用的文件,而不是config/main.php
它现在应该可以工作了检查config/console.php文件 更改数据库名、用户名和密码。 这是yiic命令使用的文件,而不是config/main.php
它现在应该可以工作了确保您没有通过MySQL手动创建
tbl_用户
或tbl_问题
表。如果它们已经存在,请删除它们,然后再次运行迁移
还要检查以确保main/config.php
和main/console.php
中的数据库连接字符串已设置为正确引用迁移应使用的数据库
为了确认它是否有效,当您的迁移实际成功时,您将得到与以下非常相似的结果,列出所采取的每个SQL操作。如果在列表中看不到采取的任何操作,则说明它没有正确运行
D:\xampp\htdocs\yii\trackstar\protected>yiic migrate
Yii Migration Tool v1.0 (based on Yii v1.1.14)
Total 1 new migration to be applied:
m140406_014347_create_user_issue_assignment_tables
Apply the above migration? (yes|no) [no]:y
*** applying m140406_014347_create_user_issue_assignment_tables
> create table tbl_issue ... done (time: 0.351s)
> create table tbl_user ... done (time: 0.405s)
> create table tbl_project_user_assignment ... done (time: 0.366s)
> add foreign key fk_issue_project: tbl_issue (project_id) references tbl_pr
oject (id) ... done (time: 0.923s)
> add foreign key fk_issue_owner: tbl_issue (owner_id) references tbl_user (
id) ... done (time: 1.066s)
> add foreign key fk_issue_requester: tbl_issue (requester_id) references tb
l_user (id) ... done (time: 1.829s)
> add foreign key fk_project_user: tbl_project_user_assignment (project_id)
references tbl_project (id) ... done (time: 1.416s)
> add foreign key fk_user_project: tbl_project_user_assignment (user_id) ref
erences tbl_user (id) ... done (time: 1.032s)
*** applied m140406_014347_create_user_issue_assignment_tables (time: 7.446s)
Migrated up successfully.
最后,在MySQL中创建表将在它们运行后隐式提交,因此在
safeDown()
和safeUp()
方法中运行代码(这些方法将以MySQL事务的形式运行代码)并不是特别有用。为简单起见,我会将每个安全方法中的代码移动到相应的“非安全”方法。确保您没有通过MySQL手动创建tbl_用户
或tbl_问题
表。如果它们已经存在,请删除它们,然后再次运行迁移
还要检查以确保main/config.php
和main/console.php
中的数据库连接字符串已设置为正确引用迁移应使用的数据库
为了确认它是否有效,当您的迁移实际成功时,您将得到与以下非常相似的结果,列出所采取的每个SQL操作。如果在列表中看不到采取的任何操作,则说明它没有正确运行
D:\xampp\htdocs\yii\trackstar\protected>yiic migrate
Yii Migration Tool v1.0 (based on Yii v1.1.14)
Total 1 new migration to be applied:
m140406_014347_create_user_issue_assignment_tables
Apply the above migration? (yes|no) [no]:y
*** applying m140406_014347_create_user_issue_assignment_tables
> create table tbl_issue ... done (time: 0.351s)
> create table tbl_user ... done (time: 0.405s)
> create table tbl_project_user_assignment ... done (time: 0.366s)
> add foreign key fk_issue_project: tbl_issue (project_id) references tbl_pr
oject (id) ... done (time: 0.923s)
> add foreign key fk_issue_owner: tbl_issue (owner_id) references tbl_user (
id) ... done (time: 1.066s)
> add foreign key fk_issue_requester: tbl_issue (requester_id) references tb
l_user (id) ... done (time: 1.829s)
> add foreign key fk_project_user: tbl_project_user_assignment (project_id)
references tbl_project (id) ... done (time: 1.416s)
> add foreign key fk_user_project: tbl_project_user_assignment (user_id) ref
erences tbl_user (id) ... done (time: 1.032s)
*** applied m140406_014347_create_user_issue_assignment_tables (time: 7.446s)
Migrated up successfully.
最后,在MySQL中创建表将在它们运行后隐式提交,因此在
safeDown()
和safeUp()
方法中运行代码(这些方法将以MySQL事务的形式运行代码)并不是特别有用。为简单起见,我会将每个安全方法中的代码移到相应的“非安全”方法。可能是您犯了错误,我所做的。yiic是一个控制台命令。在项目的config文件夹中检查console.php的db属性
它可能指向testdrive.dbsqlite默认值&该表是由它们自己创建的
至少这是我的问题
问候,,
也许你犯了错误,就像我所做的那样。yiic是一个控制台命令。在项目的config文件夹中检查console.php的db属性 它可能指向testdrive.dbsqlite默认值&该表是由它们自己创建的 至少这是我的问题 问候,,
也许你犯了错误,就像我所做的那样。yiic是一个控制台命令。在项目的config文件夹中检查console.php的db属性。检查控制台的配置 它可能指向testdrive.dbsqlite默认值&该表是由它们自己创建的 至少这是我的问题
你好,阿吉特也许你犯了错误,就像我所做的那样。yiic是一个控制台命令。在项目的config文件夹中检查console.php的db属性。检查控制台的配置 它可能指向testdrive.dbsqlite默认值&该表是由它们自己创建的 至少这是我的问题
我也有同样的问题。通过将代码移动到 公共职能 { 代码在这里 } 并通过以下命令执行迁移
shell>yiic向上迁移我也有同样的问题。通过将代码移动到 公共职能 { 代码在这里 } 并通过以下命令执行迁移 shell>yiic向上迁移