New to Yii! Cannot assign authorization scheme to user

Hello all,

My first day with Yii and i tried to follow the documentation to build authentication & authorization mechanisms.

I managed to authenticate a user using a custom mysql table, get authManager to store data in db and the problem came up while trying to assign an authorization scheme to a user.

C:\wamp\www\proj>…\yii\framework\yiic shell

Yii Interactive Tool v1.0

Please type 'help' for help. Type 'exit' to quit.

>> $auth=Yii::app()->authManager;

>> $auth->assign('user', 'SuperAdmin');

exception 'CDbException' with message 'CDbCommand failed to execute the SQL stat

ement: SQLSTATE[HY000]: General error: 1452 Cannot add or update a child row: a foreign key constraint fails (proj/authassignment, CONSTRAINT authassignment_ibfk_1 FOREIGN KEY (itemname) REFERENCES authitem (name) ON DELETE CASCADE ON UPDATE CASCADE)' in C:\wamp\www\yii\framework\db\CDbCommand.php:192

Stack trace:

#0 C:\wamp\www\yii\framework\web\auth\CDbAuthManager.php(207): CDbCommand->execute()

#1 C:\wamp\www\yii\framework\cli\commands\ShellCommand.php(98) : eval()'d code(1): CDbAuthManager->assign('user', 'SuperAdmin')

#2 C:\wamp\www\yii\framework\cli\commands\ShellCommand.php(98): eval()

#3 C:\wamp\www\yii\framework\cli\commands\ShellCommand.php(75): ShellCommand->runShell()

#4 C:\wamp\www\yii\framework\console\CConsoleCommandRunner.php(62): ShellCommand->run(Array)

#5 C:\wamp\www\yii\framework\console\CConsoleApplication.php(88): CConsoleCommandRunner->run(Array)

#6 C:\wamp\www\yii\framework\core\CApplication.php(146): CConsoleApplication->processRequest()

#7 C:\wamp\www\yii\framework\yiic.php(30): CApplication->run()

#8 C:\wamp\www\yii\framework\yiic(15): require_once('C:\wamp\www\yii…')

#9 {main}

The SuperAdmin role is already built.

Any suggestions on what i am doing wrong?

Thanks in advance.

It should be $auth->assign('SuperAdmin', 'user'). Your parameter order is wrong.

Yes indeed. Really sorry for that! My bad  :-\