yii2-gii
yii2-gii copied to clipboard
Gii - Database Exception – yii\db\Exception
This issue has originally been reported by @xerong at https://github.com/yiisoft/yii2/issues/12388. Moved here by @samdark.
I have a table 'cm_template. and i wanted to generate a model using gii. I already enabled tablePrefix in the config file as '_cm' When i tried to generate a model, i got the below error. I have tried all i could but i could not fix this error. Please note that this is my 4th software projects i would do with yii .
SQLSTATE[42000]: Syntax error or access violation: 1102 Incorrect database name '' The SQL being executed was: SHOW TABLES FROM `` Error Info: Array ( [0] => 42000 [1] => 1102 [2] => Incorrect database name '' ) ↵ Caused by: PDOException
SQLSTATE[42000]: Syntax error or access violation: 1102 Incorrect database name ''
| Q | A |
|---|---|
| Yii version | 2.0.? |
| PHP version | 5.6 |
| Operating system | win 8 |
please show your database config.
@cebe https://github.com/yiisoft/yii2/issues/12388#issuecomment-243246932
ok, please provide the input data of the gii form.
@krebse
Yes, i created a relationship with another table, cm_templateCategory. I was able to access data on FK (catId) constraints on cm_template. Please see attached mysql table.
I selected "No relation" and i was able to generate the model successfully. But my "Template" class does note contain
public function getTemCategory()
{
return $this->hasOne(TemplateCategory::className(), ['id' => 'catid']);
}
So i think selecting No Relation is not a good option for me.

@cebe , see attached gii form input data

I've backed up to gii @stable in composer and this solved my issue
Thank you mainpart. so, if i update gii, would the issue be fixed?
Good, the error has gone off after updating my composer but i was suppose to have a method that should return hasOne relation like below, unfortunately, no such method in the model class that Gii generated. Example public function getTemCategory() { return $this->hasOne(TemplateCategory::className(), ['id' => 'catid']); }
You have to downgrade it. Put "prefer-stable: true" into composer.json file and update: this will downgrade gii to 2.0.5 (as of now), solve this issue and probably will give your project more stability ;-)