Is possible to add UNIQUE constrain, to a column for a new table, using Rails migrations?
I tried like to add the constrain, while creating the table, like this:
t.string :username, unique: true
And it doesn't work
And the other option was:
add_index :authors, :username, unique: true
but it this will create a index, and will not add a unique constrain on the column.
I test it using Rails 5.2 and SQlite.
To clarify, what I trying to archive, is do same as this SQL querie:
CREATE TABLE authors(
username TEXT UNIQUE
);
but using Rails Migration, if possible.
Note that add_index option will NOT add a unique constrain on the column, even if we get a similar behavior.