aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG2
-rw-r--r--activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb5
-rw-r--r--activerecord/test/migration_test.rb3
3 files changed, 7 insertions, 3 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 698bf850e9..b2f4afd24f 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fixed migration trouble with SQLite when NOT NULL is used in the new definition #5215 [greg@lapcominc.com]
+
* Fixed problems with eager loading and counting on SQL Server #5212 [kajism@yahoo.com]
* Fixed that count distinct should use the selected column even when using :include #5251 [anna@wota.jp]
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
index cf4114aacc..7b7232ea13 100644
--- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
@@ -316,9 +316,10 @@ module ActiveRecord
def copy_table_contents(from, to, columns, rename = {}) #:nodoc:
column_mappings = Hash[*columns.map {|name| [name, name]}.flatten]
rename.inject(column_mappings) {|map, a| map[a.last] = a.first; map}
-
+ from_columns = columns(from).collect {|col| col.name}
+ columns = columns.find_all{|col| from_columns.include?(column_mappings[col])}
@connection.execute "SELECT * FROM #{from}" do |row|
- sql = "INSERT INTO #{to} VALUES ("
+ sql = "INSERT INTO #{to} ("+columns*','+") VALUES ("
sql << columns.map {|col| quote row[column_mappings[col]]} * ', '
sql << ')'
@connection.execute sql
diff --git a/activerecord/test/migration_test.rb b/activerecord/test/migration_test.rb
index 0f837841e1..88a94d8710 100644
--- a/activerecord/test/migration_test.rb
+++ b/activerecord/test/migration_test.rb
@@ -173,7 +173,8 @@ if ActiveRecord::Base.connection.supports_migrations?
Person.connection.create_table :testings do |t|
t.column :foo, :string
end
- Person.connection.add_column :testings, :bar, :string, :null => false, :default => "default"
+ Person.connection.execute "insert into testings (foo) values ('hello')"
+ assert_nothing_raised {Person.connection.add_column :testings, :bar, :string, :null => false, :default => "default" }
assert_raises(ActiveRecord::StatementInvalid) do
Person.connection.execute "insert into testings (foo, bar) values ('hello', NULL)"