Zend Framework – A table must have a primary key, but none was found
If you’re beginner using Zend_Db_Table with VIEWs and starting to hate Zend framework because of this message:
Fatal error: Uncaught exception ‘Zend_Db_Table_Exception’ with message ‘A table must have a primary key, but none was found’ in…..
Remember, that you can always specify primary key:
<?php
class Articles extends Zend_Db_Table{
protected $_name = ‘v_articles’;
protected $_primary = ‘id’;
February 6th, 2009 at 2:05 am
Hi. Your site displays incorrectly in Firefox, but content excellent! Thank you for your wise words:)
February 13th, 2009 at 10:31 pm
Thanks for the tip. Does this error get thrown when you are using the table metadata cache and the adapter fails to get the metadata back from the cache?
February 13th, 2009 at 10:41 pm
Hi Rhino,
you’ll get this error if you’re not setting primary key for a table (database design issue?…) or using views… because they don’t have primary keys. So it’s just a workaround.