LoginSignup
1
0

More than 5 years have passed since last update.

Field count is less than expected - expected x but was y

Last updated at Posted at 2018-08-09

はじめに

Android開発の勉強を始めて少し詰まったので備忘録ついでに記載します.
データベースを使って開発していると下記のエラーが出力されました.

Field count is less than expected - expected x but was y

なぜこのエラーが出たか

概要

データベースのカラム追加を行った際に,アプリケーション内に変更前のテーブルのカラムと,変更後のテーブルのカラム数が一致しないためでした.

具体例

以下に具体例および具体的な警告を示します.

変更前

ID Title Contents Date

変更後

ID Title Contents Date category

Field count is less than expected - expected 5 but was 4

解決策

解決策のフローは以下の通りです.
1. アプリケーションをアンインストール
2. 再ビルド

1をすることでアプリに付加されているRealmの設定ファイルを削除します.
2をすることで新規アプリとして新しいテーブルを作成します.

具体的な流れ

  1. 変更前のアプリケーション(カラム数4のテーブル)
  2. テーブルの変更(カラム数4→5)
  3. アプリケーションの削除(カラム数4のテーブル削除)
  4. 再ビルド(カラム数5のテーブル作成)

終わりに

android開発初心者のため分かりにくい記事になったのですが参考になればいいかなと.

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0