Doctrine Default Primary Key Problem (Again)

Posted by 01010011 on Stack Overflow See other posts from Stack Overflow or by 01010011
Published on 2010-04-26T03:28:16Z Indexed on 2010/04/26 3:33 UTC
Read the original article Hit count: 310

Filed under:
|
|

Hi,

Should I change all of my uniquely-named MySQL database primary keys to 'id' to avoid getting errors related to Doctrine's default primary key set in the plugin 'doctrine_pi.php'?

To further elaborate, I am getting the following reoccurring error, this time after trying to login to my login page:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'u.book_id' in 'field list'' in...

I suspect the problem resides at a MySQL table used for my login, of which has a primary key called

id

Marc B originally solved an identical problem for me in this post

http://stackoverflow.com/questions/2702229/doctrine-codeigniter-mysql-crud-errors

when I had the same problem with a different table within the same database. Following his suggestion, I changed the default primary key located at

system/application/plugins/doctrine_pi.php

from 'id' to 'book_id':

<?php
// system/application/plugins/doctrine_pi.php

...

// set the default primary key to be named 'id', integer, 4 bytes
Doctrine_Manager::getInstance()->setAttribute(
    Doctrine::ATTR_DEFAULT_IDENTIFIER_OPTIONS,
    array('name' => 'book_id', 'type' => 'integer', 'length' => 4));

and that solved my previous problem. However, my login page stopped working.

So what is the safe thing to do? Change all of my primary keys to 'id' (will that solve the problem without causing some other problem I am not aware of). Or should I add some lines of code in doctrine_pi.php?

© Stack Overflow or respective owner

Related posts about doctrine

Related posts about mysql