currentlyOffline

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’;

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks

This entry was posted on Sunday, November 9th, 2008 at 11:23 pm and is filed under Zend Framework. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Custom URLs in Zend Framework (v1.6.1) »

3 Responses to “Zend Framework – A table must have a primary key, but none was found”

  1. SottHaito Says:
    February 6th, 2009 at 2:05 am

    Hi. Your site displays incorrectly in Firefox, but content excellent! Thank you for your wise words:)

  2. Rhino Says:
    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?

  3. currentlyOffline Says:
    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.

Leave a Reply

  • Pages

    • About
  • Archives

    • December 2009
    • November 2009
    • September 2009
    • August 2009
    • July 2009
    • June 2009
    • May 2009
    • April 2009
    • February 2009
    • January 2009
    • November 2008
  • Categories

    • books (3)
    • Cristina Scabbia (1)
    • I hate computers… and Internet! (6)
    • Jokes (1)
    • jQuery (1)
    • Music (1)
      • italian metal (1)
      • Lacuna Coil (1)
    • Question – Answer (1)
    • randomness (3)
    • Uncategorized (2)
    • web hosting jokes (3)
    • Zend Framework (6)

currentlyOffline is proudly powered by WordPress | Bob