Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
dm constraints belongs_to "Can't create table 'dm_constraints.#sql-" bug
require 'bundler/setup'
Bundler.require :default
class List
include DataMapper::Resource
property :id, Serial
property :name, String
has n, :items, constraint: :destroy
class Item
include DataMapper::Resource
property :id, Serial
property :name, String
# uncomment this and run again
# belongs_to :list
user = "root"
pass = ""
puts `mysql -u #{user} --password=#{pass} -e 'CREATE DATABASE IF NOT EXISTS dm_constraints'`$stdout, :debug)
DataMapper.setup :default, "mysql://#{user}:#{pass}@localhost/dm_constraints"
list = List.create( name: "a list" )
items = []
items << list.items.create( name: "item one")
items << list.items.create( name: "item two")
items << list.items.create( name: "item three")
puts Item.all
# error:
# ~ Can't create table 'dm_constraints.#sql-10b_35' (errno: 150) (code: 1005, sql state: HY000, query: ALTER TABLE `items` ADD CONSTRAINT `items_list_fk` FOREIGN KEY (`list_id`) REFERENCES `lists` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, uri: mysql:root:@localhost/dm_constraints)
#/Users/makevoid/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-do-adapter-268302022ae8/lib/dm-do-adapter/adapter.rb:63:in `execute_non_query': Can't create table 'dm_constraints.#sql-10b_35' (errno: 150) (DataObjects::SQLError)
# my clue - constraints gem:
# constraints/adapters/do_adapter:71
# execute(create_constraints_statement)
def github(gem)
def gh_gem(gem)
gem gem, git: github(gem)
%w(dm-core dm-constraints dm-migrations dm-do-adapter dm-mysql-adapter).each do |g|
gh_gem g
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment