activegraph: Neo4j::DeprecatedSchemaDefinitionError - Some schema elements were defined by the model (which is no longer supported), but they do not exist in the database.

Neo4j::DeprecatedSchemaDefinitionError: Some schema elements were defined by the model (which is no longer supported), but they do not exist in the database. Run the following to create them:

  • Happens when I run the specs on my Neo4j models. I’m working on a dockerized environment.
  • RSpec works fine with any other ActiveRecord models.
  • Connection to Neo4j dev container is successful and without issues
  • Connection to Neo4j test conatiner is successful and without issues

Timeline:

  1. Create Node model
rails g model Node node_id:integer label:string unique_identifier:string representation:integer power_index:float project_support:float

It creates a migration, which is different that every video tutorial the official site has. Maybe is a new “feature”? I cannot longer work without migrations. The model also contains a serialized attributes which was not included in the cli command

class Node 
  include Neo4j::ActiveNode
  property :node_id, type: Integer
  property :label, type: String
  property :unique_identifier, type: String
  property :representation, type: Integer
  property :power_index, type: Float
  property :project_support, type: Float
  
  property :categories
  serialize :categories
end
  1. Create Node factory
FactoryGirl.define do
	sequence :unique_ident do |n|
		Faker::StarWars.quote.to_s + '#{n}'
	end
	factory :node do
		node_id { Faker::Number.number(3).to_i }
		label { Faker::StarWars.planet }
		unique_identifier { FactoryGirl.generate(:unique_ident) }
		representation { Faker::Number.number(1).to_i }
		categories { [1, 2, 3] }
		power_index { rand * 1 }
		project_support { rand * 1 }
	end
end
  1. Run the rspec command
require 'rails_helper'

RSpec.describe Node, type: :model do
  describe "when creating" do
    let(:node) { FactoryGirl.create(:node) }
    it "it is valid" do
      expect(node.valid?).to be_truthy
    end
  end
end

and the famous error comes up

docker-compose exec neo4j_rails_container **rspec spec/models/node_spec.rb**

Failures:

  1) Node when creating it is valid
     Failure/Error: let(:node) { FactoryGirl.create(:node) }
     
     Neo4j::DeprecatedSchemaDefinitionError:
                 Some schema elements were defined by the model (which is no longer supported), but they do not exist in the database.  Run the following to create them:
     
       rake neo4j:generate_schema_migration[constraint,Node,uuid]
     
     
       And then run `rake neo4j:migrate`
  1. I run the migration

docker-compose exec neo4j_rails_container **rake neo4j:migrate**

== 20170213202544 ForceCreateNodeUuidConstraint: running... ====================
 CYPHER CREATE CONSTRAINT ON (n:`Node`) ASSERT n.`uuid` IS UNIQUE 
== 20170213202544 ForceCreateNodeUuidConstraint: migrated (0.3480s) ============
  1. Run the specs again, same error.

The errors appears when the factory instance is created, so there’s something wrong with the model. Please, any idea on what I’m doing wrong is greatly appreciated.

Runtime information:

Neo4j database version: 3.1 or rather lastest (as it’s pulled from Docker Registry ) neo4j gem version: 8.0.6 neo4j-core gem version: 7.0.3

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 18 (8 by maintainers)

Most upvoted comments

First I would suggest checking out the upgrade guide:

http://neo4jrb.readthedocs.io/en/8.0.x/UpgradeGuide.html

There are a couple of big changes that we made in version 8.0 of the neo4j gem. The biggest one that you’re running into is that it is no longer possible to specify the database schema (in Neo4j the schema is just indexes and constraints) in the model and have the schema created automatically at runtime. This is because the magical behavior caused various headaches and migrations are a more deliberate mechanism for changes to the database.

In ActiveNode, all models have an id_property. If you don’t specify one this will be the uuid property by default.

You don’t need to create/specify any properties in the database because, as you say, Neo4j is schemaless (at least with regards to properties/labels/relationships). The gem does however require that there be a Neo4j uniqueness constraint on the id_property for any model. This is so that the database can enforce the uniqueness of the id_property and so that queries for the id_property can be efficient (since uniqueness constraints on a label/property come automagically with an index)

We would like to have something akin to ActiveRecord’s schema.rb file so that you don’t need to run all migrations to get the schema setup (especially for tests). This does not currently exist, unfortunately.

Also, an important thing to note is that if you’re running tests you may need to specify RAILS_ENV=test when running rake db:migrate to make sure the migrations run on your test DB rather than your development DB.

Hopefully that answers your questions! I’m going to close this issue because I don’t think there’s anything to be done, but I’m happy to continue the conversation here or re-open if there is something to do/fix

@thefliik @cheerfulstoic The issue is resolved now. The problem was with the SchemaMigration node getting deleted.

  config.before(:suite) do
    query = 'MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r'
    Neo4j::ActiveBase.current_session.query(query).to_a
  end

Reviewing the guide helped me in the track again.

Now, excluding SchemaMigration node by

  config.before(:suite) do
    query = 'MATCH (n) WHERE NOT (n:`Neo4j::Migrations::SchemaMigration`) OPTIONAL MATCH (n)-[r]-() DELETE n,r'
    Neo4j::ActiveBase.current_session.query(query).to_a
  end

fixed it.

However, I still don’t understand why the tests were not failing on my development machine. Will see to it though. Thanks for all the help.

As a clarification, DeprecatedSchemaDefinitionError could mean that you haven’t run migrations, or it could mean that you need to create migrations (which you then need to subsequently run).

Hmm, the fact that everything’s working fine on your development machine, and you’re just running into issues in the circleci environment, would lead me to guess that something’s not being configured correctly for circleci.

It’s quite possible you’ve already tried this, but what I’ve done to try and diagnose some hard problems is to create a new application which just replicates the minimum necessary to seemingly recreate the problem. If it is a bug with the id_property, you should be able to share this test app and help fix it. If it’s a problem with the setup, that should also help.