# SQL Server migration result differs depending on client

**URL:** <https://www.ruby-forum.com/t/sql-server-migration-result-differs-depending-on-client/117950>\
**Category:** Rails\
**Created:** [October 22, 2007, 6:49pm UTC](https://www.ruby-forum.com/t/sql-server-migration-result-differs-depending-on-client/117950 "2007-10-22T18:49:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![donv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/0ea827/32.png) [@donv](https://www.ruby-forum.com/u/donv)\
**Post date:** [October 22, 2007, 6:49pm UTC](https://www.ruby-forum.com/t/sql-server-migration-result-differs-depending-on-client/117950/1 "2007-10-22T18:49:20Z")

</div>

Hi all!

I hope somebody can help me. I have very little hair left, and it is  
decreasing more rapidly the longer I have this problem 🙂

I am connecting to a MS SQL Server 9.0.2047 from Fedora 7 linux, using  
freetds, unixodbc and rubyodbc. Most things work fine, just not the  
following:

I have a schema/migration like this:

create\_table “users”, :force =\> true do |t|  
t.column “username”, :string, :limit =\> 50,  
:null =\> false  
t.column “password”, :string, :limit =\> 50,  
:null =\> false  
t.column “enabled”, :boolean,  
:null =\> false  
t.column “firstName”, :string, :limit =\> 50  
t.column “lastName”, :string, :limit =\> 50  
t.column “email”, :string, :limit =\> 50  
t.column “userService”, :integer  
t.column “accessProfile\_id”, :integer  
t.column “salted\_password”, :string, :limit =\> 40  
t.column “salt”, :string, :limit =\> 40  
t.column “security\_token”, :string, :limit =\> 40  
t.column “token\_expiry”, :datetime  
t.column “deleted”, :boolean, :default =\>  
false, :null =\> false  
t.column “verified”, :boolean, :default =\>  
false  
end

When I run db:schema:load using the sqlserver adapter I get the  
following DDL (just added newlines for readability):

DROP TABLE users  
CREATE TABLE users (  
[id] int NOT NULL IDENTITY(1, 1) PRIMARY KEY,  
[username] varchar(50) NOT NULL,  
[password] varchar(50) NOT NULL,  
[enabled] bit NOT NULL,  
[firstName] varchar(50) DEFAULT NULL,  
[lastName] varchar(50) DEFAULT NULL,  
[email] varchar(50) DEFAULT NULL,  
[userService] integer DEFAULT NULL,  
[accessProfile\_id] integer DEFAULT NULL,  
[salted\_password] varchar(40) DEFAULT NULL,  
[salt] varchar(40) DEFAULT NULL,  
[security\_token] varchar(40) DEFAULT NULL,  
[token\_expiry] datetime DEFAULT NULL,  
[deleted] bit DEFAULT 0 NOT NULL,  
[verified] bit DEFAULT 0  
)

Running this using the SQL Server Management Studio gives the wanted  
result. Running the same DDL using a migration script either using the  
migration statements above or using an “execute” call, gives the wrong  
result. A dump of the table after running using ActiveRecord looks like  
this:

/\*\*\*\*\*\* Object: Table [dbo].[users] Script Date: 10/22/2007 13:03:30  
\*\*\*\*\*\*/  
CREATE TABLE [dbo].[users](  
[id] [int] IDENTITY(1,1) NOT NULL,  
[username] varchar COLLATE SQL\_Latin1\_General\_CP1\_CI\_AS NOT  
NULL,  
[password] varchar COLLATE SQL\_Latin1\_General\_CP1\_CI\_AS NOT  
NULL,  
[enabled] [bit] NOT NULL,  
[firstName] varchar COLLATE SQL\_Latin1\_General\_CP1\_CI\_AS NOT  
NULL DEFAULT (NULL),  
[lastName] varchar COLLATE SQL\_Latin1\_General\_CP1\_CI\_AS NOT NULL  
DEFAULT (NULL),  
[email] varchar COLLATE SQL\_Latin1\_General\_CP1\_CI\_AS NOT NULL  
DEFAULT (NULL),  
[userService] [int] NOT NULL DEFAULT (NULL),  
[accessProfile\_id] [int] NOT NULL DEFAULT (NULL),  
[salted\_password] varchar COLLATE SQL\_Latin1\_General\_CP1\_CI\_AS  
NOT NULL DEFAULT (NULL),  
[salt] varchar COLLATE SQL\_Latin1\_General\_CP1\_CI\_AS NOT NULL  
DEFAULT (NULL),  
[security\_token] varchar COLLATE SQL\_Latin1\_General\_CP1\_CI\_AS  
NOT NULL DEFAULT (NULL),  
[token\_expiry] NOT NULL DEFAULT (NULL),  
[deleted] [bit] NOT NULL DEFAULT ((0)),  
[verified] [bit] NOT NULL DEFAULT ((0)),  
PRIMARY KEY CLUSTERED  
(  
[id] ASC  
)WITH (PAD\_INDEX = OFF, IGNORE\_DUP\_KEY = OFF) ON [PRIMARY]  
) ON [PRIMARY]

* * *

Notice the change of NULL to NOT NULL.

* * *

What am I doing wrong? I dump the SQL in the  
file /usr/lib/ruby/site\_ruby/1.8/DBD/ODBC/ODBC.rb
