dbDelta Not Working in WordPress? Solved

I faced this today with dbDelta and the problem was; I try to use lowercase as much as possible in SQL, and dbDelta accepts only uppercase keywords.

The following SQL didn’t work with dbDelta:

create table table_name(
id int not null primary key auto_increment,
user_id int not null,
points int not null,
reason varchar(50)
)

On the other key, it worked when I have changed SQL keywords to uppercase:

CREATE TABLE $table_name(
id      INT NOT NULL PRIMARY KEY auto_increment,
user_id INT NOT NULL,
points  INT NOT NULL,
reason  VARCHAR(50)
)

A complete list of explicit constraints of dbDelta can be found here.

If you have already written your SQL with lowercase keywords, this tool will help you to format it quickly.