2010年6月2日星期三

RE: [fw-db] Zend_Db_Table_Exception : "A table must have a primary key, but none was found"

I'd say that in a properly designed database, nearly any table should have a primary key of some sort. 80/20 seems to be a bit too low, I'd say that 99% of the tables will can have a primary key.

The only reason there should be no primary key is when it is perfectly okay to have duplicate records. In most cases, people will still add an extra column with an auto incrementing id. You could also create a primary key on all columns. Also, if you have an UNIQUE index, you can promote that to be the primary key (in MySQL you can only do that when the columns are NOT NULL, but you could also specify the UNIQUE index in PHP).

Vincent de Lau
vincent@delau.nl

> -----Oorspronkelijk bericht-----
> Van: Petar Dzhambazov [mailto:jamby77@gmail.com]
> Verzonden: woensdag 2 juni 2010 14:03
> Aan: Саша Стаменковић
> CC: fw-db@lists.zend.com
> Onderwerp: Re: [fw-db] Zend_Db_Table_Exception : "A table must have a
> primary key, but none was found"
>
> It is probably the 80/20 % rule. Most of the time your tables will have
> primary keys and when they don't they are some sort of special case.
> Then you either work with adapter methods or extend Zend_Db_Table to
> fit
> your case.
>
> regards
> Petar
>
> On 06/02/2010 02:52 PM, Саша Стаменковић wrote:
> > Ah, probably to keep find() method satisfied.
> >
> > Regards,
> > Saša Stamenković
> >
> >
> > On Wed, Jun 2, 2010 at 1:51 PM, Саша Стаменковић <umpirsky@gmail.com
> > <mailto:umpirsky@gmail.com>> wrote:
> >
> > Then I don't see the reason for Zend_Db_Table to throw exception.
> > Might that be a bug?
> >
> > Regards,
> > Saša Stamenković
> >
> >
> >
> > On Wed, Jun 2, 2010 at 1:49 PM, Petar Dzhambazov
> <jamby77@gmail.com
> > <mailto:jamby77@gmail.com>> wrote:
> >
> > Hi,
> > If you set
> >
> > protected $_primary = 'your_primary_key';
> >
> > it is not being checked if it is really the private key. So
> if
> > it fits your needs you can set any filed of the table to be
> used
> > as primary key.
> >
> > regards
> > Petar
> >
> >
> > On 06/02/2010 02:19 PM, Саша Стаменковић wrote:
> >
> > But what if table have no primary key?
> >
> > Regards,
> > Saša Stamenković
> >
> >
> > On Wed, Jun 2, 2010 at 12:53 PM, Hilmar Hallbjörnsson
> > <zormoni@gmail.com <mailto:zormoni@gmail.com>
> > <mailto:zormoni@gmail.com <mailto:zormoni@gmail.com>>>
> wrote:
> >
> > Hi.
> >
> > Normally, what you need in your class is this
> variable:
> >
> > protected $_primary = 'your_primary_key'; OR
> >
> > protected $_primary = array( 'primary_1', 'primary_2'
> > .....);
> >
> > This error might occur when the model cannot detect
> the
> > primary key,
> > often it's because you have more than one.
> >
> > --Best regards and good luck
> > Hilmar
> >
> > 2010/5/25 zamanphp <zamanphp@gmail.com
> > <mailto:zamanphp@gmail.com> <mailto:zamanphp@gmail.com
> > <mailto:zamanphp@gmail.com>>>
> >
> >
> >
> > hi all
> > I'm using Zend_Cachefor Zend_Db_Table_Abstract
> > Sometimes Htay following occurs:
> > "A table must have a primary key, but none was found"
> > While I'm have in the my table primary key.
> > and Refresh the page to be resolved
> > What Is Problem؟
> >
> > --
> > View this message in context:
> > http://zend-framework-
> community.634137.n4.nabble.com/Zend-Db-Table-Exception-A-table-must-
> have-a-primary-key-but-none-was-found-tp2230044p2230044.html
> > Sent from the Zend DB mailing list archive at
> > Nabble.com.
> >
> >
> >
> >
> >
> >

没有评论: