I am developing using Rails, Docker, and MySQL.
The version is as follows.
Development environment
Ruby vresion 2.7.2
Rails version 6.0.3.4
MySQL version 5.7
We are currently creating a table for users.
Next, I'm trying to create a table (review table) that uses user as a foreign key.
docker-compose run web rails db: migrate
If i do, you will get an error.
Would you please help me?
Error message(Since the number of characters has been limited, some parts have been omitted.)
rails aborted!
StandardError: An error has occurred, all later migrations canceled:
Mysql2 :: Error: Table'share_read_development.reviews' doesn't exist
/usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:131:in `_query'
/usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:131: in `block in query'
/usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:130:in `handle_interrupt'
/usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:130:in `query'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:201: in `block (2 levels) in execute'
/usr/local/bundle/gems/activesupport-6.0.3.4/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
/usr/local/bundle/gems/activesupport-6.0.3.4/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
/usr/local/bundle/gems/activesupport-6.0.3.4/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb: 200: in `block in execute'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract_adapter.rb:722: in `block (2 levels) in log'
/usr/local/bundle/gems/activesupport-6.0.3.4/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
/usr/local/bundle/gems/activesupport-6.0.3.4/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
/usr/local/bundle/gems/activesupport-6.0.3.4/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
/usr/local/bundle/gems/activesupport-6.0.3.4/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
/usr/local/bundle/gems/activesupport-6.0.3.4/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract_adapter.rb:721:in `block in log'
/usr/local/bundle/gems/activesupport-6.0.3.4/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract_adapter.rb:712:in `log'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:199:in `execute'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/mysql/database_statements.rb:41:in `execute'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:210:in `execute_and_free'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/mysql/schema_statements.rb:11:in `indexes'/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract/schema_statements.rb: 855: in `index_name_exists?'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:1196: in `add_index_options'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/mysql/schema_creation.rb:65:in `index_in_create'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract/schema_creation.rb:49:in `block in visit_TableDefinition'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract/schema_creation.rb:49:in `map'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract/schema_creation.rb:49:in `visit_TableDefinition'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract/schema_creation.rb:14:in `accept'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:315:in `create_table'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/mysql/schema_statements.rb:81:in `create_table'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/migration.rb:890:in `block in method_missing'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/migration.rb: 858: in `block in say_with_time'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/migration.rb: 858: in `say_with_time'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/migration.rb:879:in `method_missing'
/share-read/db/migrate/20201211140012_create_reviews.rb:3:in `change'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/migration.rb: 828: in `exec_migration'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/migration.rb:812: in `block (2 levels) in migrate'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/migration.rb:811: in `block in migrate'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:471:in `with_connection'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/migration.rb:810:in `migrate'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/migration.rb:1002: in `migrate'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/migration.rb1310: in `block in execute_migration_in_transaction'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/migration.rb:1363: in `ddl_transaction'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/migration.rb:1309: in `execute_migration_in_transaction'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/migration.rb:1281: in `block in migrate_without_lock'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/migration.rb:1280:in `each'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/migration.rb:1280:in `migrate_without_lock'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/migration.rb:1229: in `block in migrate'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/migration.rb:1382:in `with_advisory_lock'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/migration.rb:1229: in `migrate'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/migration.rb:1061: in `up'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/migration.rb:1036: in `migrate'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/tasks/database_tasks.rb:238:in `migrate'
/usr/local/bundle/gems/activerecord-6.0.3.4/lib/active_record/railties/databases.rake:86:in `block (3 levels) in<main>'
/ usr/local/bundle/gems/activerecord-
Corresponding source code
Migration file
20201211140012_create_reviews
class CreateReviews</pre>
<p><strong>docker-compose.yml</strong></p>
<pre><code>version: '3'
services: services:
db:
image: mysql: 5.7
environment: environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_USER: root
ports: ports:
-"3306: 3306"
volumes:
--./db/mysql/volumes:/var/lib/mysql
web:
build: ..
command: bash -c "rm -f tmp/pids/server.pid&&bundle exec rails s -p 3000 -b '0.0.0.0'"
volumes:
--.:/Share-read
ports: ports:
-"3000: 3000"
depends_on:
--db
dockerfile
FROM ruby: 2.7.2
RUN apt-get update -qq&&apt-get install -y build-essential libpq-dev nodejs
#Install yarn package management tool
RUN apt-get update&&apt-get install -y curl apt-transport-https wget&&\
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add-&&\
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list&&\
apt-get update&&apt-get install -y yarn
Install #Node.js
RUN curl -sL https://deb.nodesource.com/setup_7.x | bash-&&\
apt-get install nodejsRUN mkdir/share-read
WORKDIR/share-read
COPY Gemfile/share-read/Gemfile
COPY Gemfile.lock /share-read/Gemfile.lock
RUN bundle install
COPY./Share-read
# Add a script to be executed every time the container starts.
COPY entrypoint.sh /usr/bin/
RUN chmod + x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000
#Start the main process.
CMD ["rails", "server", "-b", "0.0.0.0"]
databas.yml(Comments in the code are omitted.)
default:&default
adapter: mysql2
encoding: utf8mb4
pool:<% = ENV.fetch ("RAILS_MAX_THREADS") {5}%>username: root
password: password
host: db
development:
<<: * default
database: share_read_development
test: test:
<<: * default
database: share_read_test
production:
<<: * default
database: share_read_production
username: share_read
password:<% = ENV ['SHARE_READ_DATABASE_PASSWORD']%>
What I tried
docker-compose run web rails db: reset and
I tried docker-compose run web rails db: migrate: reset etc.
The error did not resolve.
Also, I checked the migration status with docker-compose db: migrate: status, but
I am using a Mac as my PC.
-
Answer # 1
Related articles
- ruby - i want to have a foreign key after creating a table
- ruby on rails - unable to create controller
- ruby - create 3 or more columns in the intermediate table | db design
- ruby - unable to create rails model (environment: cloud9)
- ruby - unable to create app database on heroku
- ruby - unable to run rake db: create rails_env = production on aws deployment
- ruby on rails - unable to start server in aws production environment
- python - create child table with django foreign key
- ruby - i want to save multiple records in an intermediate table in one process
- ruby - i want to transition from create to show with rails
- ruby - unable to get user id
- ruby - i want to create a checkbox with the opposite meaning in the rails checkbox (for the same model, i want to create a check
- ruby on rails - unable to get latitude/longitude from user registration
- ruby on rails - round-robin league table design
- ruby on rails - unable to access localhost with rails6 and docker
- mysql - [sql] cannot create table
- ruby - i can't "rails db: create rails_env = production" on aws
- i want to create a table with a javascript for statement
- ruby - [rails/rspec] intermediate table model test does not pass
- python - you may need to restart the kernel to use updated packages error
- dart - flutter: the instance member'stars' can't be accessed in an initializer error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- javascript - how to check if an element exists in puppeteer
- sh - 'apt-get' is not recognized as an internal or external command, operable program or batch file
- i want to check the type of a shell script variable
- i want to call a child component method from a parent in vuejs
After docker-compose down
I solved it by doing docker-compose up -d.
(I intended to try this as well, but I'm not sure why it was solved this time)