开发者

How to create mysql function in rails test database?

I wrote a Mysql function for my rails app and i added it to my database by manual. When i开发者_StackOverflow社区 want to test the function using Rails UNIT test, it through the errors like below

ActiveRecord::StatementInvalid: Mysql::Error: FUNCTION mydatabase.fn_Sample_Function does not exist:

How to add the function, out of the test suite or beginning of test run ?

Thanks in Advance, Aaa.


I can't see the error. But I assume the problem is your schema format.

config.active_record.schema_format = :sql

in application.rb should be what you need to do.

The reason behind that is by default your test database is not made from a schema only dump of your development database, but, instead from db/schema.rb - which knows nothing about mysql functions.

an sql schema format will do a mysqldump (or pg_dump) with the schema only flag set to true and create a development_structure.sql file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜