开发者

How to create mysql function in rails test database?

开发者 https://www.devze.com 2023-04-03 14:59 出处:网络
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

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

精彩评论

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