mishamx / yii-user

Yii PHP Framework extension for registration and management users accounts.
http://yii-user.2mx.org/
186 stars 154 forks source link

migration creates tables named {{users}} {{profiles}} and {{profiles_fields}} and then fails #45

Closed dzogchen closed 11 years ago

dzogchen commented 11 years ago

I ran the migration command as per the readme.md and it failed... here is the output Creating migration history table "tbl_migration"...done. Total 2 new migrations to be applied: m110805_153437_installYiiUser m110810_162301_userTimestampFix

Apply the above migrations? (yes|no) [no]:yes *\ applying m110805_153437_installYiiUser type db: mysql

create table {{users}} ... done (time: 0.093s) create unique index user_username on {{users}} (username) ... done (time: 0.165s) create unique index user_email on {{users}} (email) ... done (time: 0.103s) create table {{profiles}} ... done (time: 0.130s) add foreign key user_profile_id: {{profiles}} (user_id) references {{users}} (id) ... done (time: 0.149s) create table {{profiles_fields}} ... done (time: 0.109s) Admin login [admin]: Admin email [webmaster@example.com]: Admin password [admin]: insert into {{users}} ... done (time: 0.002s) insert into {{profiles}} ... done (time: 0.001s) insert into {{profiles_fields}} ... done (time: 0.001s) insert into {{profiles_fields}} ... done (time: 0.001s) *\ applied m110805_153437_installYiiUser (time: 17.428s)

*\ applying m110810_162301_userTimestampFix type db: mysql

add column create_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP to table {{users}} ... done (time: 0.110s) add column lastvisit_at TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' to table {{users}} ... done (time: 0.211s) execute SQL: UPDATE {{users}} SET create_at = FROM_UNIXTIME(createtime), lastvisit_at = IF(lastvisit,FROM_UNIXTIME(lastvisit),'0000-00-00 00:00:00') ...Exception: CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '{users}} SET create_at = FROM_UNIXTIME(createtime), lastvisit_at = IF(lastvisit,' at line 1. The SQL statement executed was: UPDATE {{users}} SET create_at = FROM_UNIXTIME(createtime), lastvisit_at = IF(lastvisit,FROM_UNIXTIME(lastvisit),'0000-00-00 00:00:00') (/Applications/MAMP/htdocs/yii-1.1.13.e9e4a0/framework/db/CDbCommand.php:357)

0 /Applications/MAMP/htdocs/yii-1.1.13.e9e4a0/framework/db/CDbMigration.php(159): CDbCommand->execute(Array)

1 /Applications/MAMP/htdocs/yii1.1/protected/modules/user/migrations/m110810_162301_userTimestampFix.php(24): CDbMigration->execute('UPDATE {{users}...')

2 /Applications/MAMP/htdocs/yii-1.1.13.e9e4a0/framework/db/CDbMigration.php(50): m110810_162301_userTimestampFix->safeUp()

3 /Applications/MAMP/htdocs/yii-1.1.13.e9e4a0/framework/cli/commands/MigrateCommand.php(385): CDbMigration->up()

4 /Applications/MAMP/htdocs/yii-1.1.13.e9e4a0/framework/cli/commands/MigrateCommand.php(109): MigrateCommand->migrateUp('m110810162301...')

5 [internal function]: MigrateCommand->actionUp(Array)

6 /Applications/MAMP/htdocs/yii-1.1.13.e9e4a0/framework/console/CConsoleCommand.php(172): ReflectionMethod->invokeArgs(Object(MigrateCommand), Array)

7 /Applications/MAMP/htdocs/yii-1.1.13.e9e4a0/framework/console/CConsoleCommandRunner.php(67): CConsoleCommand->run(Array)

8 /Applications/MAMP/htdocs/yii-1.1.13.e9e4a0/framework/console/CConsoleApplication.php(91): CConsoleCommandRunner->run(Array)

9 /Applications/MAMP/htdocs/yii-1.1.13.e9e4a0/framework/base/CApplication.php(169): CConsoleApplication->processRequest()

10 /Applications/MAMP/htdocs/yii-1.1.13.e9e4a0/framework/yiic.php(33): CApplication->run()

11 /Applications/MAMP/htdocs/yii1.1/protected/yiic.php(7): require_once('/Applications/M...')

12 /Applications/MAMP/htdocs/yii1.1/protected/yiic(4): require_once('/Applications/M...')

13 {main}

*\ failed to apply m110810_162301_userTimestampFix (time: 0.323s)

Migration failed. All later migrations are canceled.

Somehow, I can't imagine that {{users}} {{profiles}} and {{profiles_fields}} are the correct table names...

Any ideas what went wrong??

schmunk42 commented 11 years ago

You need to set a tablePrefix in your dbConnection http://www.yiiframework.com/doc/api/1.1/CDbConnection#tablePrefix-detail

dzogchen commented 11 years ago

I did!

dzogchen commented 11 years ago

Just to be clear, I added 'tablePrefix' => 'tbl_', to the 'db' array in the components array in config/main.php

schmunk42 commented 11 years ago

Which version did you download?

dzogchen commented 11 years ago

the version linked on the extensions yii site - yii-user-0.3-61-gfc69518

I will grab the zip from github and try that

dzogchen commented 11 years ago

Unfortunately, same result

schmunk42 commented 11 years ago

Sorry, I had a similar error once, but I can't remember of anything else. Last idea: "You don't overwrite your config with a local file?"

dzogchen commented 11 years ago

well, I'm running this on MAMP PRO, so config/main.php IS a local file.... Thanks for your help anyhow!

SOLVED: I added 'tablePrefix' => 'tbl_' to the 'db' section of config/console.php and now it works!....

dzogchen commented 11 years ago

My suggestion would be to add this solution to the instructions, as they only mention adding 'tablePrefix' => 'tbl_', to the main.php and not to console.php

schmunk42 commented 11 years ago

Yes that was it! Now I remember :)