# Why is this migration trying to re-create schema\_info?

**URL:** <https://www.ruby-forum.com/t/why-is-this-migration-trying-to-re-create-schema-info/119370>\
**Category:** Rails\
**Created:** [November 6, 2007, 2:00pm UTC](https://www.ruby-forum.com/t/why-is-this-migration-trying-to-re-create-schema-info/119370 "2007-11-06T14:00:31Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![fredistic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/a8b319/32.png) [@fredistic](https://www.ruby-forum.com/u/fredistic)\
**Post date:** [November 6, 2007, 2:00pm UTC](https://www.ruby-forum.com/t/why-is-this-migration-trying-to-re-create-schema-info/119370/1 "2007-11-06T14:00:31Z")

</div>

Postgresql Migration Failure on 4th migration (attachment\_fu).  
A migration fails mysteriously.

The console says:  
rake aborted!  
uninitialized constant AttachmentImages

The log says:  
SQL (0.000000) PGError: ERROR: relation “schema\_info” already  
exists  
: CREATE TABLE schema\_info (version integer)

Of course it exists, it’s up to 3.

The database is not modified.

Rails 1.2.4,  
ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32]

The failing migration looks okay to me:  
def self.up  
add\_column :images, :parent\_id, :integer  
add\_column :images, :content\_type, :string  
add\_column :images, :filename, :string  
add\_column :images, :thumbnail, :string  
add\_column :images, :size, :integer

```
add_index :images, :artist_id

```

end

fredistic

---

<div class="post-metadata">

**Author:** ![fredistic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/a8b319/32.png) [@fredistic](https://www.ruby-forum.com/u/fredistic)\
**Post date:** [November 6, 2007, 3:36pm UTC](https://www.ruby-forum.com/t/why-is-this-migration-trying-to-re-create-schema-info/119370/2 "2007-11-06T15:36:30Z")

</div>

On 6 Nov 2007, at 12:59, fredistic wrote:

> Postgresql Migration Failure on 4th migration (attachment\_fu).  
> A migration fails mysteriously.
> 
> The console says:  
> rake aborted!  
> uninitialized constant AttachmentImages

Is there a stack trace to go with that ?

Fred

---

<div class="post-metadata">

**Author:** ![fredistic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/a8b319/32.png) [@fredistic](https://www.ruby-forum.com/u/fredistic)\
**Post date:** [November 6, 2007, 6:09pm UTC](https://www.ruby-forum.com/t/why-is-this-migration-trying-to-re-create-schema-info/119370/3 "2007-11-06T18:09:53Z")

</div>

On 11/6/07, fredistic [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> exists  
> : CREATE TABLE schema\_info (version integer)
> 
> Of course it exists, it’s up to 3.

Those are two different problems. The second is unrelated to the first  
and can be ignored. AR just blindly tries to create the schema\_info in  
every migration; it ignores the “already exists” problem.

You need to investigate the AttachmentImages problem.

---

<div class="post-metadata">

**Author:** ![fredistic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/a8b319/32.png) [@fredistic](https://www.ruby-forum.com/u/fredistic)\
**Post date:** [November 6, 2007, 6:17pm UTC](https://www.ruby-forum.com/t/why-is-this-migration-trying-to-re-create-schema-info/119370/4 "2007-11-06T18:17:24Z")

</div>

fredistic wrote:

> Postgresql Migration Failure on 4th migration (attachment\_fu).  
> A migration fails mysteriously.
> 
> The console says:  
> rake aborted!  
> uninitialized constant AttachmentImages
> 
> The log says:  
> SQL (0.000000) PGError: ERROR: relation “schema\_info” already  
> exists  
> : CREATE TABLE schema\_info (version integer)
> 
> Of course it exists, it’s up to 3.
> 
> The database is not modified.
> 
> Rails 1.2.4,  
> ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32]
> 
> The failing migration looks okay to me:  
> def self.up  
> add\_column :images, :parent\_id, :integer  
> add\_column :images, :content\_type, :string  
> add\_column :images, :filename, :string  
> add\_column :images, :thumbnail, :string  
> add\_column :images, :size, :integer
> 
> ```
> add_index :images, :artist_id
> 
> ```
> 
> end

The schema\_info error indicates that something may be borked in your  
migration naming. You have confirmed that you do not have two  
migrations whose file names differ only by the number prefix, right?

If that is not the problem then what does your class  
attachment\_image(s???) \< ActiveRecord::Base in  
app/models/attachment\_image(s???).rb say? If that is consistent with  
your class name then what does your class attachment\_image(s???) \<  
ActiveRecord::Migration in the db/migrate/004\_attachment\_image(s???).rb  
migration file say?

You may have a problem with the naming of your classes if in truth you  
use plural in some places and singular in others.

Regards,

---

<div class="post-metadata">

**Author:** ![fredistic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/a8b319/32.png) [@fredistic](https://www.ruby-forum.com/u/fredistic)\
**Post date:** [November 6, 2007, 7:59pm UTC](https://www.ruby-forum.com/t/why-is-this-migration-trying-to-re-create-schema-info/119370/5 "2007-11-06T19:59:25Z")

</div>

I changed the name of the class to match the name of the .rb file and  
and it just worked. I did not understand they had to be the same.  
Perhaps I once knew and forgot? Thanks for all the help…

On Nov 6, 7:17 pm, James B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![fredistic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/a8b319/32.png) [@fredistic](https://www.ruby-forum.com/u/fredistic)\
**Post date:** [November 6, 2007, 8:11pm UTC](https://www.ruby-forum.com/t/why-is-this-migration-trying-to-re-create-schema-info/119370/6 "2007-11-06T20:11:08Z")

</div>

I changed the name of the class to match the name of the .rb file and  
and it just worked. I did not understand they had to be the same.  
Perhaps I once knew and forgot? Thanks for all the help…

On Nov 6, 7:17 pm, James B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![fredistic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/a8b319/32.png) [@fredistic](https://www.ruby-forum.com/u/fredistic)\
**Post date:** [November 6, 2007, 7:55pm UTC](https://www.ruby-forum.com/t/why-is-this-migration-trying-to-re-create-schema-info/119370/7 "2007-11-06T19:55:54Z")

</div>

F.C. asked for a stack trace. Changing the file name changes the name  
of the uninitialized constant that triggers the error, matching it.  
Here it is called 004\_imaginary.rb. So the "uninitialized constant’ it  
complains about is ‘Imaginary’. I’ve tried other names and the error  
message follows the file name.

I can use rake db:migrate VERSION=2 and 3 to go back and forth without  
a problem. Putting in ‘VERSION=4’ results in identical error  
messages, of course. Schema\_info in the database is 3.

> dir db\migrate

Directory of C:\InstantRails\rails\_apps\g1\db\migrate

11/06/2007 03:42 PM .  
11/06/2007 03:42 PM …  
10/19/2007 03:44 PM 474 001\_create\_images.rb  
10/19/2007 03:44 PM 612 002\_create\_users.rb  
10/19/2007 03:44 PM 561 003\_more\_user.rb  
11/06/2007 03:39 PM 767 004\_imaginary.rb  
4 File(s) 2,414 bytes  
2 Dir(s) 18,688,790,528 bytes free

> rake --trace db:migrate  
> (in C:/InstantRails/rails\_apps/g1)  
> \*\* Invoke db:migrate (first\_time)  
> \*\* Invoke environment (first\_time)  
> \*\* Execute environment  
> \*\* Execute db:migrate  
> rake aborted!  
> uninitialized constant Imaginary  
> C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.3/lib/  
> active\_support/dependencies.rb:266:in `load_missing_constant' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.3/lib/ active_support/dependencies.rb:452:in`const\_missing’  
> C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.3/lib/  
> active\_support/dependencies.rb:464:in `const_missing' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.3/lib/ active_support/inflector.rb:250:in`constantize’  
> C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.3/lib/  
> active\_support/core\_ext/string/inflections.rb:148:in `constantize' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.4/lib/ active_record/migration.rb:366:in`migration\_class’  
> C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.4/lib/  
> active\_record/migration.rb:346:in `migration_classes' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.4/lib/ active_record/connection_adapters/abstract_adapter.rb:128:in`inject’  
> C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.4/lib/  
> active\_record/migration.rb:342:in `each' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.4/lib/ active_record/migration.rb:342:in`inject’  
> C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.4/lib/  
> active\_record/migration.rb:342:in `migration_classes' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.4/lib/ active_record/migration.rb:330:in`migrate’  
> C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.4/lib/  
> active\_record/migration.rb:297:in `up' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.4/lib/ active_record/migration.rb:288:in`migrate’  
> C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.4/lib/tasks/  
> databases.rake:4  
> C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:  
> 399:in `call' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb: 399:in`execute’  
> C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:  
> 399:in `each' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb: 399:in`execute’  
> C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:  
> 369:in `invoke' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb: 362:in`synchronize’  
> C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:  
> 362:in `invoke' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb: 1935:in`run’  
> C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:  
> 1935:in `each' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb: 1935:in`run’  
> C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rake-0.7.2/bin/rake:7  
> C:/InstantRails/ruby/bin/rake.bat:20:in `load’  
> C:/InstantRails/ruby/bin/rake.bat:20

fredistic

---

<div class="post-metadata">

**Author:** ![fredistic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/a8b319/32.png) [@fredistic](https://www.ruby-forum.com/u/fredistic)\
**Post date:** [November 6, 2007, 9:37pm UTC](https://www.ruby-forum.com/t/why-is-this-migration-trying-to-re-create-schema-info/119370/8 "2007-11-06T21:37:28Z")

</div>

fredistic wrote:

> I changed the name of the class to match the name of the .rb file and  
> and it just worked. I did not understand they had to be the same.  
> Perhaps I once knew and forgot? Thanks for all the help…
> 
> On Nov 6, 7:17 pm, James B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Convention over configuration.

Rails depends upon the contents of its project files having class names  
consistent with its conventions and maintaining the relationship of the  
class name to the name of the containing file is one of those  
conventions.
