issue while creating model

Hello,

I am very new to yii framework and I am having issue is creating model.

My php version is,

$~[ PHP ]protected$php -v

PHP 5.2.0-8+etch13 (cli) (built: Oct 2 2008 08:26:18)

Copyright © 1997-2006 The PHP Group

Zend Engine v2.2.0, Copyright © 1998-2006 Zend Technologies

with Xdebug v2.0.3, Copyright (c) 2002-2007, by Derick Rethans

I have created an application, using webapp.

I have configured the database connection as following,

$~[ PHP ]protected$less config/main.php

       'db'=>array(


                       'class'=>'CDbConnection',


                       'connectionString' => 'pgsql:host=<ip-address>;dbname=<db-name>',


                       'username' => '<user-name>',


                       'password' => '<password>',


                  ),

After creating my application, to create a model following error is occurred saying table does not exist but the table is present in the specified database in public schema,

$~[ PHP ]protected$yiic shell config/main.php

/home/user/public_html/YII/yii-1.1.3.r2247/TESTING/protected/config/console.phpYii Interactive Tool v1.1 (based on Yii v1.1.3)

Please type ‘help’ for help. Type ‘exit’ to quit.

>> model Products product

Warning: the table ‘product’ does not exist in the database.

generate models/Products.php

  exist fixtures/product.php





        ...overwrite? [Yes|No|All|Quit]        skip fixtures/product.php

generate unit/ProductsTest.php

The following model classes are successfully generated:

Products

If you have a ‘db’ database connection, you can test these models now with:

$model=Products::model()->find();


print_r($model);

>> $model=Products::model()->find();

productexception ‘CDbException’ with message ‘The table “product” for active record class “Products” cannot be found in the database.’ in /home/user/public_html/YII/yii-1.1.3.r2247/framework/db/ar/CActiveRecord.php:2052

Stack trace:

Pleas help me overcome this issue.

Thanks in advance.

Regards,

Selvi

yiic is outdated, you can use Gii - http://www.yiiframework.com/doc/guide/topics.gii

As for the error check in your database that the table name is "product" - all lowercase…

Hello,

Thanks for ur information about gii, I’ll download and work on it, I think in YII 1.1 it will be present.

For the database model error, my table name is in lowercase only.

database=# \d product

                                        Table "product"


   Column        |          Type          |                          Modifiers                           

---------------------±-----------------------±-------------------------------------------------------------

product_id | integer | not null default nextval(‘product_product_id_seq’::regclass)

product_name | character varying(100) |

product_flavor | character varying(100) |

product_version | character varying(50) |

product_description | text |

product_status | boolean |

Indexes:

"product_pkey" primary key, btree (product_id)

In spite the table is present it reports error saying table not found.

Note: In postgres the table names are case-insensitive.

Regards,

Selvi

Aren’t you using Yii 1.1.3 ?

I saw in your post that you are using yii-1.1.3.r2247 so Gii is there…

I remember that when I was starting using Yii version 1.1.0 and postgress I had to put


'tablePrefix'=>'',

because it was by default "tbl_", but this was solved in new versions…

anyway try that one like:




'tablePrefix'=>'',

'connectionString' => 'pgsql:host=<ip-address>;dbname=<db-name>',

                           'username' => '<user-name>',

                           'password' => '<password>',



Yes I am using 1.1.3, but I was not knowing that gii is the feature of it.

To say about model creation error, even after adding the ‘tablePrefix’=>’’, the same problem persists.

changed the main.php,

[i]$~[ PHP ]protected$less config/main.php

‘db’=>array(

‘class’=>‘CDbConnection’,

‘tablePrefix’=>’’,

‘connectionString’ => ‘pgsql:host=<ip-address>;dbname=<db-name>’,

‘username’ => ‘<user-name>’,

‘password’ => ‘<password>’,

),[/i]

[i]$~[ PHP ]protected$yiic shell config/main.php

/home/user/public_html/YII/yii-1.1.3.r2247/TESTING/protected/config/console.phpYii Interactive Tool v1.1 (based on Yii v1.1.3)

Please type ‘help’ for help. Type ‘exit’ to quit.

>> model Products product

Warning: the table ‘product’ does not exist in the database.

generate models/Products.php

exist fixtures/product.php

…[/i]

For database I have configured only in config/main.php, do I need to configure it in some other files.

Thanks.

I’m out of ideas… could be something with privileges?

I have given full permission, such as chmod -R 777 <YII Application Directory>.

Interface per say, I am able to use the basic interface developed using yiic webapp.

I was thinking about database privileges…

Yes database privileges are given.

Hence I am able to access from that machine and operate.

Kindly help me overcome this issue, I not able to connect to the database.

Shall I create model files without using shell, and create the file products.php in models directory and do the required operation.

[font="Arial Black"]While trying I have got a surprising thing, when the model created of the table test_bkdbi it is created, whereas for other tables it is not. But both the tables have same details. [/font]

[font="Arial Black"]-> Creating model for table called hello.[/font]

$~[ PHP ]protected$./yiic shell config/main.php

Yii Interactive Tool v1.1 (based on Yii v1.1.3)

Please type ‘help’ for help. Type ‘exit’ to quit.

>> model hello

Warning: the table ‘hello’ does not exist in the database.

generate models/hello.php

generate fixtures/hello.php

generate unit/helloTest.php

The following model classes are successfully generated:

hello

If you have a ‘db’ database connection, you can test these models now with:

&#036;model=hello::model()-&gt;find();


print_r(&#036;model);

[font="Arial Black"]-> Creating model for table called test_bkdbi.[/font]

$~[ PHP ]protected$./yiic shell config/main.php

Yii Interactive Tool v1.1 (based on Yii v1.1.3)

Please type ‘help’ for help. Type ‘exit’ to quit.

>> model test_bkdbi

generate models/test_bkdbi.php

generate fixtures/test_bkdbi.php

generate unit/test_bkdbiTest.php

The following model classes are successfully generated:

test_bkdbi

If you have a ‘db’ database connection, you can test these models now with:

&#036;model=test_bkdbi::model()-&gt;find();


print_r(&#036;model);

[font="Arial Black"]Table contents.[/font]

bkdbi=# \d hello

           Table &quot;bkdbi.hello&quot;

Column | Type | Modifiers

--------±----------------------------±----------

no | integer |

name | text |

date | timestamp without time zone |

bkdbi=# \d test_bkdbi

        Table &quot;public.test_bkdbi&quot;

Column | Type | Modifiers

--------±----------------------------±----------

no | integer |

name | text |

date | timestamp without time zone |

[font=“Arial Black”]How this is so,???.[/font]

Any help is very much appreciated.

Thanks in advance.

One thing is different…

hello is in bkdbi.hello

and test_bkdbi is in public.test_bkdbi

Yes, that was the problem, since in by default it will search for tables in public schema, I have understood where I was wrong.

Thanks a lot sir. :) :D ::) :rolleyes:

Your good documentation (table content) helped me to help you :D