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.

[Solved] Add a column to a table

edited August 2011 in Vanilla 2.0 - 2.8
I am new to Vanilla. I made small hacks for 'Viscacha' before. Creating Addons for Vanilla is the first time I get in touch with an Addon-system.
Now there is one problem: I want to add a column to a table. The query is easy but Vanilla does not do what I want it to do:
My first idea was to make it like that:

public function Setup() {
$query = mysql_query("ALTER TABLE `gdn_discussion` ADD `Visible` BOOLEAN NOT NULL DEFAULT '1' AFTER `Sink`");
if(!($query)) {
die("Fatal Error: ".mysql_error());

When I enable the Addon, the script is fired and $query is true. But it does not add a Visible column to the gdn_discussion table.

I searched for an alternative and I found something like that


It does not work either. Am I too stupid to read the (fucking) manual? Am I too stupid to use an Addon system? Am I too stupid to use PHP?

Thanks for any help!

Edit: Not answered: I failed to click the right button.

Best Answer


  • UnderDogUnderDog MVP
    Answer ✓
    if you enter the query into phpMyAdmin does it add a column to the table or does it fail there too? Maybe it's something with the table prefix.
  • edited August 2011
    It is no problem to add the column by phpmyadmin.

    Mysterious: Now the Vanilla Addon-Management shows me an error, that there is no database selected. I will try to fix that.

    Edit: Now I tried this thing:

    ->Column('Name', 'varchar(255)')
    ->Column('Type', 'varchar(128)')
    ->Column('Size', 'int(11)')
    ->Column('InsertUserID', 'int(11)')
    ->Column('DateInserted', 'datetime')
    ->Column('ForeignID', 'int(11)', TRUE)
    ->Column('ForeignTable', 'varchar(24)', TRUE)
    ->Set(FALSE, FALSE);

    The test table (with prefix gdn_) was created successfully. Now I am looking for a function in the Gdn class which can add columns. I followed some calls and recently I am in the factory class. I think I took the wrong path to the solution, didn't I?

    Oh, now I am at the mysql_structure-class. I think I am in touch with the solution. I think I can do it alone. Thanks for your help, though.

    Now I fixed the problem using this code:

    ->Column('Visible', array('yes', 'no'), 'yes')

    ->Column('Visible', array('yes', 'no'), 'yes')

    I do not know why it did not work before.
Sign In or Register to comment.