Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Dataobject advice needed


Reply


4 Posts   1475 Views

Avatar
Harley

Community Member, 153 Posts

1 September 2009 at 12:24pm

Edited: 01/09/2009 12:24pm

Ok so I have a client page which I want to create a new tab for where I will be able to add people to. What I'm looking to do though is utilise the 'members' table in the database so I can also give these people access to the Forum and also add them to a security group as they both use the same table.

I have no idea really how to do this, here is my code:

   function getCMSFields_forPopup() {
      $fields = new FieldSet();
      $fields->push( new TextField( 'FirstName', 'First name' ) );
      $fields->push( new TextField( 'Surname', 'Surname' ) );
      $fields->push( new TextField( 'NickName', 'Nick name' ) );
      $fields->push( new TextField( 'Email', 'Email' ) );
      $fields->push( new PasswordField( 'Password', 'Password' ) );
      return $fields;
   }

But right now I am just recieving an error:

[User Error] Couldn't run query: ALTER TABLE `ClientMember` ADD `FirstName` mediumtext character set utf8 collate utf8_general_ci, ADD `Surame` mediumtext character set utf8 collate utf8_general_ci, ADD `NickName` mediumtext character set utf8 collate utf8_general_ci Duplicate column name 'FirstName'
GET /wwwroot/elevator/dev/build?flush=1

Thanks in advance

Avatar
Willr

Forum Moderator, 5513 Posts

1 September 2009 at 5:12pm

Looks like FirstName has been defined twice in the database? Have you got multiple decorators? Can you post the whole error log somewhere so I can see the backtrace.

Avatar
Harley

Community Member, 153 Posts

2 September 2009 at 6:52am

Hi Will, thanks for the reply

Here is the whole error:

[User Error] Couldn't run query: ALTER TABLE `ClientMember` ADD `FirstName` mediumtext character set utf8 collate utf8_general_ci, ADD `Surame` mediumtext character set utf8 collate utf8_general_ci, ADD `NickName` mediumtext character set utf8 collate utf8_general_ci Duplicate column name 'FirstName'
GET /wwwroot/elevator/dev/build/?flush=1
Line 400 in C:\xampp\htdocs\wwwroot\elevator\sapphire\core\model\MySQLDatabase.php

Source
391    }
392    
393    function databaseError($msg, $errorLevel = E_USER_ERROR) {
394       // try to extract and format query
395       if(preg_match('/Couldn\'t run query: ([^\|]*)\|\s*(.*)/', $msg, $matches)) {
396          $formatter = new SQLFormatter();
397          $msg = "Couldn't run query: \n" . $formatter->formatPlain($matches[1]) . "\n\n" . $matches[2];
398       }
399       
400       user_error($msg, $errorLevel);
401    }
402 }
403
404 /**
405 * A result-set from a MySQL database.
406 * @package sapphire
Trace
Couldn't run query: ALTER TABLE `ClientMember` ADD `FirstName` mediumtext character set utf8 collate utf8_general_ci, ADD `Surame` mediumtext character set utf8 collate utf8_general_ci, ADD `NickName` mediumtext character set utf8 collate utf8_general_ci Duplicate column name 'FirstName'
Line 400 of MySQLDatabase.php
MySQLDatabase->databaseError(Couldn't run query: ALTER TABLE `ClientMember` ADD `FirstName` mediumtext character set utf8 collate utf8_general_ci, ADD `Surame` mediumtext character set utf8 collate utf8_general_ci, ADD `NickName` mediumtext character set utf8 collate utf8_general_ci | Duplicate column name 'FirstName',256)
Line 102 of MySQLDatabase.php
MySQLDatabase->query(ALTER TABLE `ClientMember` ADD `FirstName` mediumtext character set utf8 collate utf8_general_ci, ADD `Surame` mediumtext character set utf8 collate utf8_general_ci, ADD `NickName` mediumtext character set utf8 collate utf8_general_ci)
Line 206 of MySQLDatabase.php
MySQLDatabase->alterTable(ClientMember,Array,Array,Array,Array)
Line 163 of Database.php
Database->endSchemaUpdate()
Line 197 of DatabaseAdmin.php
DatabaseAdmin->doBuild(,1)
Line 100 of DatabaseAdmin.php
DatabaseAdmin->build()
Line 135 of DevelopmentAdmin.php
DevelopmentAdmin->build(HTTPRequest)
Line 129 of RequestHandler.php
RequestHandler->handleRequest(HTTPRequest)
Line 122 of Controller.php
Controller->handleRequest(HTTPRequest)
Line 277 of Director.php
Director::handleRequest(HTTPRequest,Session)
Line 121 of Director.php
Director::direct(/dev/build/)
Line 118 of main.php

Avatar
Hamish

Community Member, 712 Posts

2 September 2009 at 9:26am

Edited: 02/09/2009 9:29am

You've made some sort of change to an object that the build process is trying to mirror in your database. This error is not related to the client page code you posted originally (which looked fine). Note this line:

[User Error] Couldn't run query: ALTER TABLE `ClientMember` ADD `FirstName` mediumtext character set utf8 collate utf8_general_ci, ADD `Surame` mediumtext character set utf8 collate utf8_general_ci, ADD `NickName` mediumtext character set utf8 collate utf8_general_ci Duplicate column name 'FirstName'

It is trying to ALTER TABLE `ClientMember`. Please post the code for the ClientMember class. Note also that "Surname" appears to be misspelled.

I strongly suspect that you've created a ClientMember class that you are trying to use to decorate the Member object, but (as the error says) you have a "Duplicate column name 'FirstName'".