Comments (5)
You should provide default value (DEFAULT ... clause in ALTER TABLE statement) when adding column with NOT NULL constraint for non-empty table .
by Raimonds Simanovskis
from dm-migrations.
Ok, we’ll need to look into adapting dm-migrations appropriately. Thanks!
by Alex Coles
from dm-migrations.
This actually seems like a valid constraint for dm-migrations to have across the board. You really can’t add a NOT NULL constraint to a non-empty table without a default, otherwise the database will be in an invalid state.
I would think we should raise an exception when a column with a NOT NULL constraint is added to a non-empty table with no default. We should instruct people to either provide the default value in the declaration, or have them do a three step process:
- add the column, but allow NULL
- populate every column so none of them are NULL
- modify the column to add the NOT NULL constraint
I’m not that familiar with Oracle, but I’d hope that this process would work too (some googling says it will, but if @rsim could confirm I’d appreciate it).
Of course we want people to use the first approach (the one @rsim recommends above), but sometimes the default values have to be calculated from some other data, so the second approach would work for that.
by Dan Kubb (dkubb)
from dm-migrations.
Yes, this three step process will work on Oracle as well. If you add NOT NULL constraint on existing column then Oracle will go through all table rows and will validate if there are no NULL values in this column.
by Raimonds Simanovskis
from dm-migrations.
That seems reasonable. I would expect a good database to check all the existing data before adding a constraint. Whether it’s a NOT NULL constraint, a new foreign key or even a shorter length on a CHAR; that seems like the safest approach to take.
by Dan Kubb (dkubb)
from dm-migrations.
Related Issues (20)
- dm-migrations contains hardcoded SQL HOT 1
- auto_upgrade doesn't work with property type change HOT 3
- AutoUpgrades fail on STI models. HOT 7
- change_column produces bad SQL on Postgres HOT 5
- Migrating from one dbms backend to another HOT 1
- NoMethodError: undefined method `variable_value' (JRuby 1.6.3 and dm-mysql-adapter)
- auto_upgrade! within a Postgres migration creates bad create table sql HOT 1
- rename_column sql syntax is incorrect HOT 4
- Explicit migrations cannot lookup DataMapper Property constants with dm-rails and Ruby 1.8.7
- auto-migration specs fail with syntax error on mysql 14.14
- Alter column length on migration for PostgreSQL db fails due to incorrect syntax HOT 1
- Better fallback for defauls on autoupgrade opration?
- doesn't migrate repositories which are not :default HOT 2
- Support creation of composite primary keys
- Issues with db:setup and db:migrate HOT 3
- Can't convert nil into Hash when using a type from dm-types
- dm-migrations needs a new maintainer. HOT 1
- SQLite and required field without default adds 'DEFAULT NULL'
- Running tests on migrations as given in example fails HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dm-migrations.