データベースを更新し、usersデータモデルを作成するために下記を実行したところ、、
% rails db:migrate
Warning: the running version of Bundler (2.2.32) is older than the version that created the lockfile (2.2.33). We suggest you to upgrade to the version that created the lockfile by running `gem install bundler:2.2.33`.
と警告が出る。
↓
% gem install bundler:2.2.33
Fetching bundler-2.2.33.gem
Successfully installed bundler-2.2.33
Parsing documentation for bundler-2.2.33
Installing ri documentation for bundler-2.2.33
Done installing documentation for bundler after 3 seconds
1 gem installed
この状態で再度 rails db:migrate を試すも、、
% rails db:migrate
Running via Spring preloader in process 1788
== 20220110000241 CreateUsers: migrating ======================================
-- create_table(:users)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
you can't redefine the primary key column 'id'. To define a custom primary key, pass { id: false } to create_table.
/Users/chiharatomoya/Desktop/portfolio/mo-vie/db/migrate/20220110000241_create_users.rb:4:in `block in change'
/Users/chiharatomoya/Desktop/portfolio/mo-vie/db/migrate/20220110000241_create_users.rb:3:in `change'
<internal:/Users/chiharatomoya/.rbenv/versions/3.0.3/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
<internal:/Users/chiharatomoya/.rbenv/versions/3.0.3/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
-e:1:in `<main>'
調べてみたのですが、idをわざわざ定義しようとしなくても、勝手にidは反映されるので再定義しなくていいとのこと。
なので、idを定義していた一文を消します。(画像)
https://gyazo.com/5f17f452baa250030e29241b3099b9d1
% rails db:migrate
Running via Spring preloader in process 1973
== 20220110000241 CreateUsers: migrating ======================================
-- create_table(:users)
-> 0.0043s
== 20220110000241 CreateUsers: migrated (0.0047s) =============================
問題なく実行できました。
一応rails sでサーバーを実行し、/usersを見てみます。
https://gyazo.com/4c30d2ccb3b720d429cf5873d5a1f5fb
(userモデルが作成できました。)