Quick question about new columns added to an existing xf column

DJ XtAzY

Active member
#1
So I've been creating some in-house addons and it's been doing great...until I disable them. I did add new columns (varchar types) to an existing xenforo table. Basically my question is that if I do create new columns and add them to an existing xf table, should I set them to default to NULL? I did extend DataWriter so I guess when I disable the addon, the original DataWriter class doesn't know what values to set for those extra columns. I just learned this now from Mike's quote:

If you're adding columns to existing tables, you must add a default value. Why? It's not for your code, it's not for the data writer.

It's for when people disable your add-on (or if someone does happen to insert into the DB without a data writer).
 

Brogan

XenForo moderator
Staff member
#2
What are the columns for and how does the code utilise the content?
Depending on the use you may need to set them to NULL, 0, or something else.
 

Chris D

XenForo developer
Staff member
#3
Yeah, as Paul says, every column you add to a default table should have a default value. What that is, is sort of irrelevant. It could be anything.

The exception is BLOB and TEXT and several other field types and their variants. These cannot accept a default value. So for those field types you should allow NULL.
 
Top