#define MDB_PAGE_FULL  (-30786)
        /** Database contents grew beyond environment mapsize */
 #define MDB_MAP_RESIZED        (-30785)
-#define MDB_LAST_ERRCODE       MDB_MAP_RESIZED
+       /** Operation is incompatible with database */
+#define MDB_INCOMPATIBLE       (-30784)
+#define MDB_LAST_ERRCODE       MDB_INCOMPATIBLE
 /** @} */
 
 /** @brief Statistics for a database in the environment */
 
        "MDB_CURSOR_FULL: Internal error - cursor stack limit reached",
        "MDB_PAGE_FULL: Internal error - page has no more space",
        "MDB_MAP_RESIZED: Database contents grew beyond environment mapsize",
+       "MDB_INCOMPATIBLE: Operation is incompatible with database",
 };
 
 char *
                                        if (!exact)
                                                return MDB_NOTFOUND;
                                        mdb_node_read(mc->mc_txn, leaf, &data);
+                                       /* The txn may not know this DBI, or another process may
+                                        * have dropped and recreated the DB with other flags.
+                                        */
+                                       if (mc->mc_db->md_flags != *(uint16_t *)
+                                               ((char *) data.mv_data + offsetof(MDB_db, md_flags)))
+                                               return MDB_INCOMPATIBLE;
                                        memcpy(mc->mc_db, data.mv_data, sizeof(MDB_db));
                                }
                                if (flags & MDB_PS_MODIFY)