Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dzogchen opened this issue Jun 25, 2013 · 10 comments

Comments

@dzogchen
Copy link

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 [[email protected]]:
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('m110810_162301_...')
#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
Copy link
Contributor

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

@dzogchen
Copy link
Author

I did!

@dzogchen
Copy link
Author

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

@schmunk42
Copy link
Contributor

Which version did you download?

@dzogchen
Copy link
Author

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
Copy link
Author

Unfortunately, same result

@schmunk42
Copy link
Contributor

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
Copy link
Author

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 dzogchen reopened this Jun 25, 2013
@dzogchen
Copy link
Author

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
Copy link
Contributor

Yes that was it! Now I remember :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants