I am new to Yii(Still Learning) I am following a book tutorial here I did as it was written in the book created a new migrate
yiic migrate create create_issu
Probably you are doing the mistake, What i did. yiic is a console command. Check your db properties for console.php in config folder for your project.
It might be pointing to testdrive.db SQLite default one & the table is created their.
Atleast this was my problem.
Regards, Ajeet
Check the config/console.php file Change the dbname, the username and password. This is the file that the yiic command uses, not config/main.php It should work now
Make sure you haven't created the tbl_user
or tbl_issue
tables manually via MySQL. If they exist already, drop them and then run your migration again.
Also check to make sure your database connection strings in main/config.php
AND main/console.php
are set up to correctly reference the database the migration should use.
To confirm that it worked, when your migration actually succeeds, you'll get results very similar to the following, listing each SQL action taken. If you don't see any actions taken in the list, it didn't run correctly.
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.
Finally, creation of tables in MySQL will implicitly commit after they're run, so running your code in the safeDown()
and safeUp()
methods, which will run your code as MySQL transactions, isn't especially useful. For simplicity, I would move the code in each safe method to the respective "non-safe" method.
Creating table usually don't require transactions
<?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');
}
}
If transaction is required
follows the comment of safeUp:
This method contains the logic to be executed when applying this migration. This method differs from up() in that the DB logic implemented here will be enclosed within a DB transaction. Child classes may implement this method instead of up() if the DB logic needs to be within a transaction.
Probably you are doing the mistake, What i did. yiic is a console command. Check your db properties for console.php in config folder for your project. check your configs for console.
It might be pointing to testdrive.db SQLite default one & the table is created their.
Atleast this was my problem.
Regards, Ajeet
I just dry ran you code in it created the tables alright so I have to assume it's something wrong with what your calling. Only thing that immediatly sticks out is that your running a bash script rather than the bat script.
yiic is a bash script. On Windows it is recommended to run yiic.bat or yiic.php.
Can you run php from the command line? If so: