Hi,
I try to generate crud methods from the quickstart docs: http://www.yiiframew...start.first-app but it fails complaining
about missing primary key.
First I created the table "tbl_user" from the mysql example.
Then in the yiic shell:
model User tbl_user
crud User
Fails with the error : "Error: Table "tbl_user" does not have a primary key."
My table looks like this:
mysql> describe tbl_user ;
+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| username | varchar(128) | NO | | NULL | |
| password | varchar(128) | NO | | NULL | |
| email | varchar(128) | NO | | NULL | |
php version is 5.2.8 and mysql version is 5.1.45
Any ideas ?
thanks ,
ola
Page 1 of 1
CRUD Operations fails on example table "tbl_user" CRUD Operations: Error: Table "tbl_user" does not have a prima
#3
Posted 11 April 2010 - 12:22 PM
I created the table primary key , and autoincrement:
CREATE TABLE tbl_user (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
username VARCHAR(128) NOT NULL,
password VARCHAR(128) NOT NULL,
email VARCHAR(128) NOT NULL
);
In the CrudCommand.php class, the primary key is null:
public function generateController($source,$params)
{
list($controllerClass,$modelClass)=$params;
$model=CActiveRecord::model($modelClass);
$id=$model->tableSchema->primaryKey;
// ---------------------------------
// This code fails throws exception:
// ---------------------------------
if($id===null)
throw new ShellException(Yii::t('yii','Error: Table "{table}" does not have a primary key.',array('{table}'=>$model->tableName())));
ola
CREATE TABLE tbl_user (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
username VARCHAR(128) NOT NULL,
password VARCHAR(128) NOT NULL,
email VARCHAR(128) NOT NULL
);
In the CrudCommand.php class, the primary key is null:
public function generateController($source,$params)
{
list($controllerClass,$modelClass)=$params;
$model=CActiveRecord::model($modelClass);
$id=$model->tableSchema->primaryKey;
// ---------------------------------
// This code fails throws exception:
// ---------------------------------
if($id===null)
throw new ShellException(Yii::t('yii','Error: Table "{table}" does not have a primary key.',array('{table}'=>$model->tableName())));
ola
#4
Posted 11 April 2010 - 01:48 PM
Tried to debug some more: Wrote a small test to retreive metadata from the primary key, and can't see anything wrong:
$DB = new PDO("mysql:host=$hostname;dbname=mytestdatabase", $username, $password);
$select = $DB->query('SELECT id FROM tbl_user');
$meta = $select->getColumnMeta(0);
var_dump ( $meta);
Output is
array(7) {
["native_type"]=>
string(4) "LONG"
["flags"]=>
array(2) {
[0]=>
string(
"not_null"
[1]=>
string(11) "primary_key"
}
["table"]=>
string(
"tbl_user"
["name"]=>
string(2) "id"
["len"]=>
int(11)
["precision"]=>
int(0)
["pdo_type"]=>
int(2)
}
$DB = new PDO("mysql:host=$hostname;dbname=mytestdatabase", $username, $password);
$select = $DB->query('SELECT id FROM tbl_user');
$meta = $select->getColumnMeta(0);
var_dump ( $meta);
Output is
array(7) {
["native_type"]=>
string(4) "LONG"
["flags"]=>
array(2) {
[0]=>
string(

[1]=>
string(11) "primary_key"
}
["table"]=>
string(

["name"]=>
string(2) "id"
["len"]=>
int(11)
["precision"]=>
int(0)
["pdo_type"]=>
int(2)
}
#5
Posted 12 April 2010 - 01:07 PM
That's very strange. Could you execute SQL "SHOW COLUMNS FROM tbl_user" and see the results?
Could you also exit the "yiic shell" and re-enter it to generate the model class?
Could you also exit the "yiic shell" and re-enter it to generate the model class?
#6
Posted 13 April 2010 - 12:37 PM
Hi,
I'm using mysq:
mysql> desc tbl_user ;
+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| username | varchar(128) | NO | | NULL | |
| password | varchar(128) | NO | | NULL | |
| email | varchar(128) | NO | | NULL | |
+----------+--------------+------+-----+---------+----------------+
ola
I'm using mysq:
mysql> desc tbl_user ;
+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| username | varchar(128) | NO | | NULL | |
| password | varchar(128) | NO | | NULL | |
| email | varchar(128) | NO | | NULL | |
+----------+--------------+------+-----+---------+----------------+
ola
#7
Posted 26 April 2010 - 12:12 AM
Ola, on 11 April 2010 - 06:13 AM, said:
Hi,
I try to generate crud methods from the quickstart docs: http://www.yiiframew...start.first-app but it fails complaining
about missing primary key.
First I created the table "tbl_user" from the mysql example.
Then in the yiic shell:
model User tbl_user
crud User
Fails with the error : "Error: Table "tbl_user" does not have a primary key."
Dear use crud tbl_user istead of crud user, look on your data base table that how it is defined in database, your crud query depend on your table name.
My table looks like this:
mysql> describe tbl_user ;
+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| username | varchar(128) | NO | | NULL | |
| password | varchar(128) | NO | | NULL | |
| email | varchar(128) | NO | | NULL | |
php version is 5.2.8 and mysql version is 5.1.45
Any ideas ?
thanks ,
ola
I try to generate crud methods from the quickstart docs: http://www.yiiframew...start.first-app but it fails complaining
about missing primary key.
First I created the table "tbl_user" from the mysql example.
Then in the yiic shell:
model User tbl_user
crud User
Fails with the error : "Error: Table "tbl_user" does not have a primary key."
Dear use crud tbl_user istead of crud user, look on your data base table that how it is defined in database, your crud query depend on your table name.
My table looks like this:
mysql> describe tbl_user ;
+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| username | varchar(128) | NO | | NULL | |
| password | varchar(128) | NO | | NULL | |
| email | varchar(128) | NO | | NULL | |
php version is 5.2.8 and mysql version is 5.1.45
Any ideas ?
thanks ,
ola
Zahid Mughal
#8
Posted 26 April 2010 - 12:13 AM
Ola, on 11 April 2010 - 06:13 AM, said:
Hi,
I try to generate crud methods from the quickstart docs: http://www.yiiframew...start.first-app but it fails complaining
about missing primary key.
First I created the table "tbl_user" from the mysql example.
Then in the yiic shell:
model User tbl_user
crud User
Fails with the error : "Error: Table "tbl_user" does not have a primary key."
My table looks like this:
mysql> describe tbl_user ;
+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| username | varchar(128) | NO | | NULL | |
| password | varchar(128) | NO | | NULL | |
| email | varchar(128) | NO | | NULL | |
php version is 5.2.8 and mysql version is 5.1.45
Any ideas ?
thanks ,
ola
I try to generate crud methods from the quickstart docs: http://www.yiiframew...start.first-app but it fails complaining
about missing primary key.
First I created the table "tbl_user" from the mysql example.
Then in the yiic shell:
model User tbl_user
crud User
Fails with the error : "Error: Table "tbl_user" does not have a primary key."
My table looks like this:
mysql> describe tbl_user ;
+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| username | varchar(128) | NO | | NULL | |
| password | varchar(128) | NO | | NULL | |
| email | varchar(128) | NO | | NULL | |
php version is 5.2.8 and mysql version is 5.1.45
Any ideas ?
thanks ,
ola
************************
Dear use crud tbl_user instead of crud user, look on your data base table that how it is defined in database, your crud query depend on your table name.
Zahid Mughal
#9
Posted 26 April 2010 - 07:08 AM
I kind of get it to work with just using the table name:
model tbl_user
crud tbl_user
but the app blows up when i try to create a new user. And it also require me to type the auto increment id in the create user form wich
is not correct.
PHP Error
Description
Cannot modify header information - headers already sent by (output started at /usr/local/yii/framework/db/ar/CActiveRecord.php:327)
model tbl_user
crud tbl_user
but the app blows up when i try to create a new user. And it also require me to type the auto increment id in the create user form wich
is not correct.
PHP Error
Description
Cannot modify header information - headers already sent by (output started at /usr/local/yii/framework/db/ar/CActiveRecord.php:327)
Share this topic:
Page 1 of 1