Pls Help with Primary Key issue.
- Single Page
Posted 26 July 2012 - 13:10 PM
I have the following table:
CREATE TABLE IF NOT EXISTS `tv_categories` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`ID`),
KEY `nome` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
--
-- Dump dei dati per la tabella `tv_categories`
--
INSERT INTO `tv_categories` (`ID`, `name`) VALUES
(1, 'FICTION');
And.. i have the following code:
// Setting Up Grocery CRUD System.
$crud = new grocery_CRUD();
// CRUD: Selecting database table.
$crud->set_table('tv_categories');
// CRUD: Rendering data.
$output = $crud->render();
AND... i have the following ERROR:
Fatal error: Uncaught exception 'Exception' with message 'On the state "edit" the Primary key cannot be null' in C:\wamp\www\application\libraries\grocery_crud.php on line 2465.
I have read in previous threads that this might be caused by a missing "auto_increment" property on the primary key. But as you can see, it's all there.
What is goin wrong???
Thank you.
Posted 26 July 2012 - 16:36 PM
Hm, it is weird. Please, tell me whether you have ID with "0" value at you tv_categories table? And what versions of CodeIgniter and grocery CRUD do you use?
Posted 26 July 2012 - 18:57 PM
Sorry didn't read all your code , check out if the primary field is ok - if it's auto_incrementing properly.
Posted 27 July 2012 - 07:03 AM
If you still having problems with your primary key you can try:
$crud->set_primary_key('ID');
Posted 27 July 2012 - 08:16 AM
A couple of things:
1 - The primary key has been set since the beginning. Thus this might be a bug.
2 - In the end, i've copied the example code in my project, and stepping backwards i've modified line by line to reach my original code.
I don't know but surely, you can't put the Grocery code in the index() function of a controller. That's for sure folks
By the way, thanks for te responses. This product is absolutely awesome!!