DBFlow icon indicating copy to clipboard operation
DBFlow copied to clipboard

JSONModel ForeignKey not null

Open OptimistNot opened this issue 11 years ago • 1 comments

I got an issue, when i try to save model with foreign key that has notNull condition equals true, ex: @Column(columnType = Column.FOREIGN_KEY, references = {@ForeignKeyReference(columnType = String.class, columnName = Columns.USERNAME_FK, foreignColumnName = User.Columns.USERNAME)}, notNull = true, saveForeignKeyModel = true) ForeignKeyContainer user_foreign; it gives me "Caused by: android.database.sqlite.SQLiteConstraintException: NOT NULL constraint failed: User.user_full_name (code 1299)". The model that has foreign key and i try to save is this: JSONObject json = new JSONObject(); JSONModel JSON_FPA = new JSONModel<>(json, FinalProductAudit.class); JSON_FPA.save(false);

any hALP please?

OptimistNot avatar Apr 08 '15 10:04 OptimistNot

@OptimistNot it appears the user_full_name was null. By setting nonNull() = true you cannot pass the field as null. So either before saving the object check for null or specify a onNullConflict()

agrosner avatar Apr 08 '15 13:04 agrosner