1

I have an pre-existing database named exam_prep in postgresql, which i am using in flask.

I have created a new Rails application and i want to use that database with it.

So far I have run rake db:structure:dump, which created a structure.sql under the db folder.

After that I ran db:structure:load, but got the following error:

psql:/Users/namangupta/Desktop/app/db/structure.sql:49: ERROR: type "batch_types_enum" already exists rake aborted! failed to execute: psql -v ON_ERROR_STOP=1 -q -f /Users/namangupta/Desktop/app/db/structure.sql exam_prep Please check the output above for any errors and make sure that `psql` is installed in your PATH and has proper permissions. /Users/namangupta/.rvm/gems/ruby-2.3.4/gems/activerecord-5.1.4/lib/active_record/tasks/postgresql_database_tasks.rb:108:in `run_cmd' /Users/namangupta/.rvm/gems/ruby-2.3.4/gems/activerecord-5.1.4/lib/active_record/tasks/postgresql_database_tasks.rb:80:in `structure_load' /Users/namangupta/.rvm/gems/ruby-2.3.4/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:223:in `structure_load' /Users/namangupta/.rvm/gems/ruby-2.3.4/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:236:in `load_schema' /Users/namangupta/.rvm/gems/ruby-2.3.4/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:255:in `block in load_schema_current' /Users/namangupta/.rvm/gems/ruby-2.3.4/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:304:in `block in each_current_configuration' /Users/namangupta/.rvm/gems/ruby-2.3.4/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:303:in `each' /Users/namangupta/.rvm/gems/ruby-2.3.4/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:303:in `each_current_configuration' /Users/namangupta/.rvm/gems/ruby-2.3.4/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:254:in `load_schema_current' /Users/namangupta/.rvm/gems/ruby-2.3.4/gems/activerecord-5.1.4/lib/active_record/railties/databases.rake:290:in `block (3 levels) in <top (required)>' /Users/namangupta/.rvm/gems/ruby-2.3.4/gems/rake-12.3.0/exe/rake:27:in `<top (required)>' /Users/namangupta/.rvm/gems/ruby-2.3.4/bin/ruby_executable_hooks:15:in `eval' /Users/namangupta/.rvm/gems/ruby-2.3.4/bin/ruby_executable_hooks:15:in `<main>' Tasks: TOP => db:structure:load (See full trace by running task with --trace) 

I want Rails to use the database and make a models within this. Any ideas?

1 Answer 1

2

The db:structure:load rake task creates a tables and columns from the structure.sql or schema.rb. You shouldn't need to run it, as your existing database already has all the tables you need.

Your next step would be to go about creating your model files and pointing them at the appropriate tables.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot! How can i create model that would point to the tables. I created a model simply by running the command rails g model model_name but when i opened the rails console and try to access the table entries i got nothing!
Have you pointed to the original database in config/database.yml?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.