Jump to:

22994 Posts in 11843 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » Dataobject advice needed

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

Page: 1
Go to End
Author Topic: 1289 Views
  • Harley
    Avatar
    Community Member
    153 Posts

    Dataobject advice needed Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: Dataobject advice needed Link to this post

    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.

  • Harley
    Avatar
    Community Member
    153 Posts

    Re: Dataobject advice needed Link to this post

    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

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Dataobject advice needed Link to this post

    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'".

    1289 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.