Migrations enable a developer to generate a database structure using a series of Ruby script files (each of which is an individual migration) to define database operations.

(This is typically how you would code a database for a PHP application.) However, things have moved on in the Rails world.

The Rails developers came up with a pretty good (not perfect, but pretty good) mechanism for generating databases without the need for SQL: it's called migrations, and is a part of Active Record.

According to Postgres doc, PRIMARY_KEY constraint is a combination of a unique constraint and a not-null constraint.

We have following migration: I don’t like this solution because I love readability of helper methods than SQL.

I suppose it might be worth downloading my production DB and running annotate against that and seeing if the "not null" changes in the model annotations.

What if you want to use different column as your primary key? NOTE: This article is written for Rails 4.1.1 /w Postgres My webstore uses a special string ID, called The above output clearly indicates that at DB level, is is NOT NULL, is PRIMARY_KEY and indexed.

I've already cleared cache and all that between changes, so I know that's not the issue. Here's my file (as downloaded from the builder: /** * @license Copyright (c) 2003-2013, CKSource - Frederico Knabben.

In an application we are developing, there are various things and related models that could influence a product's stock.

The name of the database table is, by convention, the pluralized (in the English language), lower-case form of the model's class name.