Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #6621 (closed defect: wontfix)

Opened 4 years ago

Last modified 3 years ago

Error reproducing TEXT column when creating table in test database using rake db:test:clone

Reported by: drewnoakes Assigned to: David
Priority: normal Milestone: 1.x
Component: ActiveRecord Version: 1.1.6
Severity: normal Keywords: text column rake clone db:test:clone clone_schema schema dumper
Cc: bitsweat

Description

I'm trying to use rake to run my tests, only it gets caught on an error when trying to create the test database's tables. I'm not that intimate with rake's internals, but here's what I've deduced so far.

The error I'm seeing is:

C:\dndotcom\rails>rake
(in C:/dndotcom/rails)
c:/ruby/bin/ruby -Ilib;test "c:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake/rake_test_loader.rb" "test/functional/tab_controller_test.rb" "test/functional/user_controller_test.rb"
Loaded suite c:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake/rake_test_loader
Started
EEEEEEEEEEEEEEEEEEEEEEEEEE...
.........
Finished in 0.734 seconds.

  1) Error:
test_create(TabControllerTest):
ActiveRecord::StatementInvalid: Mysql::Error: #42S02Table 'dndotcom_test.transcripts' doesn't exist: DELETE FROM transcripts
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/abstract_adapter.rb:120:in `log'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/mysql_adapter.rb:184:in `execute'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/mysql_adapter.rb:199:in `delete'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/fixtures.rb:283:in `delete_existing_fixtures'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/fixtures.rb:256:in `create_fixtures'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/fixtures.rb:256:in `each'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/fixtures.rb:256:in `create_fixtures'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/abstract/database_statements.rb:51:in `transaction'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/fixtures.rb:255:in `create_fixtures'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:794:in `silence'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/fixtures.rb:248:in `create_fixtures'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/fixtures.rb:565:in `load_fixtures'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/fixtures.rb:512:in `setup_with_fixtures'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/fixtures.rb:547:in `setup'

If I specify the rake task to create the test database, I get varying behaviour:

C:\dndotcom\rails>rake db:test:clone
(in C:/dndotcom/rails)
rake aborted!
Mysql::Error: #42000BLOB/TEXT column 'content' can't have a default value: CREATE TABLE transcripts (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `song_name` varchar(80) DEFAULT '' NOT NULL, `artist_name` varchar(80) DEFAULT '' NOT NULL, `album_name`varchar(80) DEFAULT '', `song_year` int(10), `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL, `content` text DEFAULT '' NOT NULL, `transcript_by_name` varchar(50), `transcript_by_email` varchar(50), `view_count` int(10) DEFAULT 0 NOT NULL) ENGINE=InnoDB

(See full trace by running task with --trace)

C:\dndotcom\rails>rake db:test:clone_structure
(in C:/dndotcom/rails)

C:\dndotcom\rails>

"rake db:test:clone_structure" creates the database table successfully, whereas "rake db:test:clone" generates the error shown. Of note is the segment: `content` text DEFAULT '' NOT NULL

If I execute "show create table transcriptions" on my dev database, here's the result:

mysql> show create table transcripts \G
*************************** 1. row ***************************
       Table: transcripts
Create Table: CREATE TABLE `transcripts` (
  `id` int(11) NOT NULL auto_increment,
  `song_name` varchar(80) NOT NULL default '',
  `artist_name` varchar(80) NOT NULL default '',
  `album_name` varchar(80) default '',
  `song_year` int(10) default NULL,
  `created_at` datetime NOT NULL,
  `updated_at` datetime NOT NULL,
  `content` text NOT NULL,
  `transcript_by_name` varchar(50) default NULL,
  `transcript_by_email` varchar(50) default NULL,
  `view_count` int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.00 sec)

Note that the TEXT column 'content' does not have a default value: `content` text NOT NULL

Does the code invoked by "rake" or "rake db:test:clone" make a mistake and compose erroneous SQL for the test database, or have I missed something. I've been working with this problem for a while and it's driving me nuts! :)

Thanks in advance for your help. I hope this isn't just a newbie annoyance. I'll happily provide extra information as required.

Change History

11/15/06 08:57:59 changed by bitsweat

  • cc set to bitsweat.
  • version set to 1.1.6.

clone_structure uses the straight sql dump whereas clone uses the ruby schema dumper which appears to have a bug in this case. Thanks for the report!

You can work around the problem by setting

  config.active_record.schema_format = :sql

in config/environment.rb

11/15/06 10:46:57 changed by drewnoakes

  • keywords changed from text rake clone db:test:clone to text column rake clone db:test:clone clone_schema schema dumper.

Thanks bitsweat. I suspected something like that was the problem, but wasn't sure. I really appreciate the workaround. Oh, and yes I am using 1.1.6.

05/24/07 01:22:01 changed by josh

  • status changed from new to closed.
  • resolution set to wontfix.