· 8 years ago · Mar 14, 2018, 06:46 PM
1# encoding: utf-8
2
3require 'rubygems'
4require 'dm-core'
5
6DataMapper.setup(:default,
7 :adapter => 'mysql',
8 :host => 'localhost',
9 :username => 'root',
10 :database => 'dm_core_test',
11 :encoding => 'UTF-8'
12)
13
14DataObjects::Mysql.logger = DataObjects::Logger.new(STDOUT, :debug)
15
16class Company
17 include DataMapper::Resource
18
19 property :id, Serial
20 property :name, String
21 has n, :invoices, :child_key => [:owner_id]
22end
23
24class Invoice
25 include DataMapper::Resource
26
27 property :id, Serial
28 property :nr, Integer
29 belongs_to :owner, :model => "Company", :child_key => [:owner_id]
30end
31
32DataMapper.auto_migrate!
33
34# Sun, 25 Oct 2009 14:00:43 GMT ~ debug ~ (0.000078) SET sql_auto_is_null = 0
35# Sun, 25 Oct 2009 14:00:43 GMT ~ debug ~ (0.000075) SET SESSION sql_mode = 'ANSI,NO_BACKSLASH_ESCAPES,NO_DIR_IN_CREATE,NO_ENGINE_SUBSTITUTION,NO_UNSIGNED_SUBTRACTION,TRADITIONAL'
36# Sun, 25 Oct 2009 14:00:43 GMT ~ debug ~ (0.079298) DROP TABLE IF EXISTS `companies`
37# Sun, 25 Oct 2009 14:00:43 GMT ~ debug ~ (0.002240) DROP TABLE IF EXISTS `invoices`
38# Sun, 25 Oct 2009 14:00:43 GMT ~ debug ~ (0.000273) SHOW TABLES LIKE 'companies'
39# Sun, 25 Oct 2009 14:00:43 GMT ~ debug ~ (0.000296) SHOW VARIABLES LIKE 'character_set_connection'
40# Sun, 25 Oct 2009 14:00:43 GMT ~ debug ~ (0.000249) SHOW VARIABLES LIKE 'collation_connection'
41# Sun, 25 Oct 2009 14:00:43 GMT ~ debug ~ (0.080663) CREATE TABLE `companies` (`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `name` VARCHAR(50), PRIMARY KEY(`id`)) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci
42# Sun, 25 Oct 2009 14:00:43 GMT ~ debug ~ (0.000250) SHOW TABLES LIKE 'invoices'
43# Sun, 25 Oct 2009 14:00:44 GMT ~ debug ~ (0.173635) CREATE TABLE `invoices` (`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `nr` INTEGER, `owner_id` INT(10) UNSIGNED NOT NULL, PRIMARY KEY(`id`)) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci
44# Sun, 25 Oct 2009 14:00:44 GMT ~ debug ~ (0.154411) CREATE INDEX `index_invoices_owner` ON `invoices` (`owner_id`)
45# /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/adapters/data_objects_adapter.rb:72:in `execute_non_query': Field 'owner_id' doesn't have a default value (DataObjects::SQLError)
46# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/adapters/data_objects_adapter.rb:72:in `block in execute'
47# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/adapters/data_objects_adapter.rb:283:in `with_connection'
48# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/adapters/data_objects_adapter.rb:70:in `execute'
49# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/adapters/data_objects_adapter.rb:119:in `block in create'
50# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/adapters/data_objects_adapter.rb:92:in `each'
51# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/adapters/data_objects_adapter.rb:92:in `create'
52# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/repository.rb:124:in `create'
53# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:877:in `_create'
54# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:669:in `create_hook'
55# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/extlib-0.9.14/lib/extlib/hook.rb:299:in `block in create_hook'
56# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/extlib-0.9.14/lib/extlib/hook.rb:297:in `catch'
57# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/extlib-0.9.14/lib/extlib/hook.rb:297:in `create_hook'
58# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:553:in `save_self'
59# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:927:in `_save'
60# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:344:in `save'
61# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/model.rb:610:in `_create'
62# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/model.rb:401:in `create'
63# from domigrate.rb:52:in `<main>'