Question

I wrote a Mysql function for my rails app and i added it to my database by manual. When i 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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top