⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Pls Help with Primary Key issue.



LukasKaine

LukasKaine
  • profile picture
  • Member

Posted 26 July 2012 - 13:10 PM

Ok i think this mod is awesome. But i can't get it to work properly.

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.

noskov.biz

noskov.biz
  • profile picture
  • Member

Posted 26 July 2012 - 16:36 PM

Hi, LukasKaine and welcome to the forum!

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?

xxaxxo

xxaxxo
  • profile picture
  • Member

Posted 26 July 2012 - 18:57 PM

you MUST have a primary key in order for groceryCRUD to work. I've encountered this - just add a field with primary status and you will be ok

Sorry didn't read all your code , check out if the primary field is ok - if it's auto_incrementing properly.

web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 27 July 2012 - 07:03 AM

Hello [member='LukasKaine'] and from me.

If you still having problems with your primary key you can try:


$crud->set_primary_key('ID');

LukasKaine

LukasKaine
  • profile picture
  • Member

Posted 27 July 2012 - 08:16 AM

Ok somehow now it works.
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!!