我在exam_prep
中有一个名为postgresql
的预先存在的数据库,我在flask
中使用该数据库。
我创建了一个新的Rails应用程序,我想用它来使用该数据库。
到目前为止,我已经运行rake db:structure:dump
,在structure.sql
文件夹下创建了db
。
之后我运行db:structure:load
,但收到以下错误:
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)
我希望Rails使用数据库并在其中创建模型。有什么想法吗?
答案 0 :(得分:2)
db:structure:load
rake任务会从structure.sql
或schema.rb
创建表格和列。您不应该运行它,因为您现有的数据库已经包含了您需要的所有表。
下一步是创建模型文件并将它们指向适当的表格。