mercredi 8 juillet 2015

Rails Migration - Constraints not working

I'm a new to Ruby on Rails (switched from Laravel) and don't understand how the migration constraints work.

In my migration file I have:

t.string :username, null: false, limit: 20
t.index :username, unique: true

But when I try to create a user with a username length that exceed the limit of 20 characters (or with no value), it works, only the unique constraint works and give me a warning if I try to create a second user with the same username.

I use sqlite for development. When I look into development.sqlite3 file, everything seems OK:

"username" varchar(20) NOT NULL

If someone could help me, it would be much appreciated :)

Thanks

Aucun commentaire:

Enregistrer un commentaire