Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Questions: how to ignore the Setup() if Column already exists in db-table?

oliverraduneroliverraduner ✭✭
edited June 2010 in Vanilla 2.0 - 2.8
I have a Plugin that adds a new Column to the Database Table "User".

Because of testing, this Column has already been created and has even already some values in it.
Now I have the problem, that I cannot activate the Plugin anymore - because it fails telling "Column already exists".

How can I get over this error by using something like "If Column X already exists, do no DB-Setup; else do it"?

Comments

  • TimTim Vanilla Staff
    How are you adding the column?

    Vanilla Forums COO [GitHub, Twitter, About.me]

  • @Tim like this:
    public function Setup()
    {
    $Structure = Gdn::Structure();
    $Structure->Table('User')
    ->Column('MyColumn', 'varchar', 40)
    ->Set(FALSE, FALSE);
    }
  • TimTim Vanilla Staff
    Are you trying to make a varchar(40)? That doesn't look like the correct syntax.

    Try:
    public function Setup()
    {
    $Structure = Gdn::Structure();
    $Structure->Table('User')
    ->Column('MyColumn', 'varchar(40)')
    ->Set(FALSE, FALSE);
    }

    Vanilla Forums COO [GitHub, Twitter, About.me]

  • oliverraduneroliverraduner ✭✭
    edited June 2010
    Are you sure?? I got this from the documentation here:
    http://vanillaforums.org/page/DatabaseStructure

    Did I miss-interpet that docu?

    [Update]
    Oh you're right - thanks for pointing this out. I changed the code and could now successfully enable the plugin again!
Sign In or Register to comment.