Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

r3613@asus: jeremy | 2005-09-26 22:25:04 -0700

 Handle sequence reset for empty tables and models with custom primary keys.

git-svn-id: 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit f5f7beb3692a2919943f44b10b29852b30f8fb1e 1 parent 1697851
@jeremy jeremy authored
2  activerecord/CHANGELOG
@@ -1,5 +1,7 @@
+* Clean up Fixtures.reset_sequences for PostgreSQL. Handle tables with no rows and models with custom primary keys. #2174 []
* Improve error message when nil is assigned to an attr which validates_size_of within a range. #2022 [Manuel Holtgrewe <>]
* Make update_attribute use the same writer method that update_attributes uses.
4 activerecord/lib/active_record/fixtures.rb
@@ -252,9 +252,9 @@ def self.reset_sequences(connection, table_names)
table_names.flatten.each do |table|
if table_class = table.to_s.classify.constantize rescue nil
pk = table_class.columns_hash[table_class.primary_key]
- if pk and == 'id' and pk.type == :integer
+ if pk and pk.type == :integer
- "SELECT setval('#{table}_id_seq', (SELECT MAX(id) FROM #{table}), true)",
+ "SELECT setval('#{table}_#{}_seq', (SELECT COALESCE(0, MAX(#{}))+1 FROM #{table}), false)",
'Setting Sequence'
Please sign in to comment.
Something went wrong with that request. Please try again.