Gii model generator can't find tables in test database

I was going to report a bug, but since I’m new to Yii, I don’t know if this is the desired behavior.

What steps will reproduce the problem?

Following along in Agile Web Application Development book

  1. Create two databases (mine were trackstar_dev and trackstar_test)

  2. Set up one database under db in config/main.php (_dev in my case)

  3. Set up the other database under db in config/test.php

  4. Add one table with same name to both databases. Model generator works in this instance.

  5. Add another table to the test database only. Model generator does not work, fails with “Table ‘tablename’ does not exist”

What is the expected output? What do you see instead?

Expect Gii to generate a model; get “Table ‘tablename’ does not exist” error.

What version of the product are you using? On what operating system?

Yii 1.1.7; Wampserver 2.1 (Apache 2.2.17, PHP 5.3.4, MySQL 5.1.53); Win7 Pro x64; Firefox 4

Please provide any additional information below.

I thought that any time a test database was specified, it would be used instead of the main database? Is this just for PHPUnit testing?

Gii uses the database component set in config/main.php… in your case this is _dev database… that’s why it cannot find the table in the other database…

I, too, am new to Yii and am having the same issue with Model Generation using Gii. In my case my config.main.php has:


		'db'=>array(

			'connectionString' => 'oci:dbname=localhost:1521/XE',

			'username' => 'dev',

			'password' => 'dev',

		),

and my database has a table tbl_user, which I can access using the regular PDO_OCI drivers in php like:




            $pdo = new PDO('oci:dbname=localhost:1521/XE', 'dev', 'dev' );

            $sth = $pdo->prepare( 'SELECT * FROM tbl_user' );

            $sth->execute();

            echo '<table border="1">';

            while( $result = $sth->fetch(PDO::FETCH_ASSOC)){

                if( $rownum < 1 ){

                    echo '<tr>';

                    foreach( array_keys($result) as $rowKey ){

                        echo "<th>$rowKey</th>";

                    }

                    echo '</tr>';

                    $rownum++;

                }

                echo '<tr>';

                foreach( $result as $key=>$item ){

                    echo '<td>'.$item. '</td>';

                }

             echo '</tr>';

            }

            print '</table>';



but Gii generated the following error in my log:

So, me being the clever chap that I am, I changed [font="Lucida Console"]COciSchema::createTable()[/font] to a [font="Lucida Console"]public[/font] function and then I got the error (also in the log):

I removed the [font="Lucida Console"]abstract[/font] tag from [font="Lucida Console"]CDbSchema::loadTable[/font] function and then I got this error (on the Gii interface):

I had assumed that my issue was that I was using Oracle, but then I ran across this post and realize that might not be my issue.

Anyone have any insight?

Thanks,

Tim

Ubuntu 10.04

Apache2

PHP5

Oracle 10 & XE

One thing to note is that if I change my [font="Lucida Console"]connectionString[/font] at all in my config/main.php, I get a error that I can not connect to the database. Therefore, I think it is fair to assume that

[list=1]

[*]I am using the right file

[*]the way I have it entered is correct

[*]the script is connecting to the DB

[/list]but then something is going terribly wrong.

Also of note is that I have tried to use the schema name in addition to the table name with the same results as I get without the schema name.

Thanks,

Tim

Ubuntu 10.04

Apache2

PHP5

Oracle 10 & XE

I may have found my answer or just confused myself more than ever…

I tried to run [font="Lucida Console"]protected/yiic shell[/font] from the command line and got the following error:

I have no /usr/local.lib/php/extensions folder at all.

This is all strange since, as my last post indicated, it appears I am establishing a connection and my phpinfo indicates that I have PDO set up for [font="Lucida Console"]mysql, oci, sqlite, sqlite2[/font]…

Anyway, I went ahead since it was just a warning [my activity in bold]:

and I seem to have a model called User. So, I press on…

weird.

Anyone have any insight into what I am doing wrong?

Thanks,

Tim

Ubuntu 10.04

Apache2

PHP5

Oracle 10 & XE

Yii-1.1.8r3324

You’ll have to start with this section of The Definitive Guide to Yii.

/Tommy

Thanks, tri

When I run the requirements checker I get:

Thanks, tri

When I run the requirements checker I get:

Ok, so the warning message probably is related to some uninstalled version of pdo.so (I guess you can find the line trying to load the library near the end of php.ini). I run Ubuntu 10.04 myself and doesn’t have the /usr/local/lib/php/extensions directory. Unfortunately I haven’t worked in an Oracle DB environment since version 7.3.

You also already mentioned that the connection seems to work.

I notice you use upper case table names. Perhaps this wiki or this thread help you out?

Perhaps you should try a simple DAO query like this one. Paste it into e.g actionIndex() of SiteController. (Omit the double braces though, since you didn’t specify a tablePrefix in the ‘db’ component.)




$sql='SELECT * FROM {{user}}';

$users=Yii::app()->db->createCommand($sql)->queryAll();



/Tommy

Thanks, Tommy…

I am now more confused than ever. Your last post took me to my php.ini where I found this line:


extension=pdo-oci.so

So, I did a:


locate pdo-oci.so

and got nothing. Hmmm… without an .so file it still can somehow connect? Then I noticed that is should be an underscore (_) not a dash(-), but I still can’t locate it. So, I tried to follow this page to re-install the pdo-oci.so and I get the following (my actions are in bold):

Arrggggg. I can’t even PHPIZE it?

I also tried to follow these instructions and which adds a [font="Lucida Console"]./configure --with-pdo-oci=instantclient,/opt/instantclient_11_2,11.2[/font] command. Ignoring the [font="Lucida Console"]phpize[/font] errors if I run that I get

What in the heck am I doing wrong??

Please advise.

Thanks,

Tim

Ubuntu 10.04

Apache2

PHP5

Oracle 10 & XE

Yii-1.1.8r3324

By the way, I may be slow, but even I am not too dumb to find where the [font="Lucida Console"]oci.h[/font] file and [font="Lucida Console"]include[/font] directory are:

Since I have my [font="Lucida Console"]ORACLE_HOME[/font] set to [font="Lucida Console"]/opt/instantclient_11_2/[/font], I would assume that should be pretty easy to find. I also have added [after this failed] a symlink to directly in the [font="Lucida Console"]ORACLE_HOME[/font] directory to include – just in case it was looking there. Still same error.

I don’t have a solution for the (re-)installation.

I think you misunderstood my previous post. Sorry for being unclear. Since just a warning message is displayed, the requirements are met and it seems like you can connect, I suggested that trying a very simple DAO query might be a good next step (that might give more clues).

/Tommy

Tommy,

Thanks for sticking with me on this. You are appreciated.

I did a modified version of what you had, but put it in my – in my [font="Lucida Console"]protected/views/site/pages/about.php[/font] – I added:





$sql='SELECT * FROM TBL_USER';

$users=Yii::app()->db->createCommand($sql)->queryAll();


$print_r = print_r( $users, true );

echo "<pre>$print_r</pre>";



and I got:

so, even though I am not able to find the right drivers on my system, I am not only connecting, but actually able to do some work on the db. Not exactly what I was expecting… I was actually hoping it would fail because then I would have a lead to figure this out.

Not sure what to do now. Monday I was excited about using Gii to help me create my first Yii app, I am now rather discouraged. It has taken me two days and still have no idea why it is not working. Not only had it consumed two days, but I have totally exhausted all of my known options, so I have no idea where to go from here.

If anyone out there can shed even a sliver of light on this, it would be appreciated.

Thanks,

Tim

Ubuntu 10.04

Apache2

PHP5

Oracle 10 & XE

Yii-1.1.8r3324

Tim,

First, I noticed the warning message was about pdo.so so I guess you may try reinstall/update php instead of pdo-oci.so.

I felt like I’d read something Oracle related very recently.

I searched and I found this ticket. This means you should definitely update your copy of the framework (or at least the file in question), from svn or by downloading the nightly tarball.

Edit: Sorry that ticket seems to be about CRUD. You are not there yet. What about give Gii another try creating the model.

Another interesting next step would be a DAO query for "SHOW CREATE TABLE your_table"

BTW did you restore the original Oracle schema files?

Edit2:

Here’s some more you can do. In the config file comment out the following line in the log component config (all levels will be enabled).


//'levels'=>'error, warning',

Then examine the generated SQL for clues, in protected/runtime/application.log.

There’s a number of Oracle threads in the forum, try a Google search for “site:yiiframework.com oracle create model”.

/Tommy

Tommy,

You are a genius! I read that and BANG! something went off in my head. I suddenly remembered that when I was setting up Yii originally I read a forum post that linked to another thread that linked to an article that linked somewhere [I can’t even find that page now] that talked about how the /db/schema/oci files didn’t work so they had developed a new version. Like a moron I trusted them blindly and used their db/schema/oci files instead of the ones that came with the Yii zip. Not only was I dumb enough to blindly follow, but I also, then, forgot all about it [vacations will do that] until you said something, so it never occurred to me that that might be the issue. So, I replaced the files with the ones from the Yii zip into the db/schema/oci folder and it fired right up.

Bravo, Tommy, bravo!

Lessons learned:

  • Trust the original files – at least give them a chance to fail

  • Write down any changes that are made to the original files – because changes will be the highest probability of error

  • Don’t start an installation right before vacation and then try to fix it without remembering [or reading your notes about] what had already been done.

  • Solve the right problem – I was chasing my tail over a non-issue when if I had looked at what the real problem was I would have seen it right away.

Thanks a ton. You are my hero.

Tim

I am also experiencing the same issue, also new to Yii. Basically I have to change my database credentials in the main.php ? I was also under the impression when you setip the db under config/test.php Yii would use the information here primarily and not the database credentials in the main.php.

Questioning the issue because the book "Agile Web Application Development with Yii 1.1 and PHP5" never mentions to go back and edit your configurations in your main in chapter 6.

Turns out that that setup was suppose to happen on your _dev not your _test, later within the chapter it says;

i have sampe problem my connectionString is correct but i have this problem:Table ‘useraccount’ does not exist.in gii model generator.anybody can help me?