This django Migration Operation can be used to transfer a fields default value to the database scheme.
Project description
Django Add Default Value
========================
Django Migration Operation that can be used to transfer a field's default value
to the database scheme.
[![PyPi](https://img.shields.io/pypi/v/django-add-default-value.svg?branch=master)](https://pypi.python.org/pypi/django-add-default-value/)
[![License](https://img.shields.io/github/license/3yourmind/django-add-default-value.svg)](./LICENSE)
[![Contributing](https://img.shields.io/badge/PR-welcome-green.svg)](https://github.com/3YOURMIND/django-add-default-value/pulls)
[![3yourminD-Careers](https://img.shields.io/badge/3YOURMIND-Hiring-brightgreen.svg)](https://www.3yourmind.com/career)
[![Stars](https://img.shields.io/github/stars/3YOURMIND/django-add-default-value.svg?style=social&label=Stars)](https://github.com/3YOURMIND/django-add-default-value/stargazers)
Dependencies
------------
* MySQL (or compatible)
* PostgreSQL
* Microsoft SQL Server
Installation
------------
`pip install django-add-default-value`
You can then use ``AddDefaultValue`` in your migration file to transfer the default
values to your database. Afterwards, it's just the usual ``./manage.py migrate``.
Usage
-----
Add this manually to a autogenerated Migration, that adds a new field::
AddDefaultValue(
model_name='my_model',
name='my_field',
value='my_default'
)
### Example
Given the following migration::
operations = [
migrations.AddField(
field=models.CharField(default='my_default', max_length=255),
model_name='my_model',
name='my_field',
),
]
Modify the migration to add a default value::
+from django_add_default_value import AddDefaultValue
+
operations = [
migrations.AddField(
field=models.CharField(default='my_default', max_length=255),
model_name='my_model',
name='my_field',
),
+ AddDefaultValue(
+ model_name='my_model',
+ name='my_field',
+ value='my_default'
+ )
]
If you check ``python manage.py sqlmigrate [app name] [migration]``,
you will see that the default value now gets set.
Contributing
------------
First of all, thank you very much for contributing to this project. Please base
your work on the ``master`` branch and target ``master`` in your pull request.
There are a few packages needed on the host system. For ubuntu the following
commands will install these
```text
apt-get install freetds-dev unixodbc-dev tdsodbc
```
Then add the following text to `/etc/odbcinst.ini`:
```ini
[FreeTDS]
Description=FreeTDS unixODBC Driver
Driver=/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup=/usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
```
To succesfully use the `dbshell` management command (very useful for debugging),
the client binaries for the respective database engines are needed.
Then install [pipenv](https://pipenv.readthedocs.io/en/latest/install/#installing-pipenv).
Edit the `Pipfile` to select your Django version and the accompanying MS-SQL
driver. Make sure you don't commit this change in any pull request - we always
set it to the oldest supported version.
Once you've updated the Pipfile, run `pipenv install --python 3 --dev`. You
should now have a working development environment as a virtualenv. To access it,
run `pipenv shell` or prefix commands with `pipenv run`. For more information
see the [pipenv documentation](https://pipenv.readthedocs.io/en/latest/basics/).
### Testing
Copy the relevant sample settings file in `test_project` to the file without
`.sample` in it. Adjust the values to match your environment (or match your
environment to the values).
You should now be able to run the tests using `tox`. Select your environment
when needed, using the `-e` command line flag. See
[Tox's excellent documentation](https://preview.tinyurl.com/y3faq6ab).
Roadmap
-------
- 0.1: Better and maintainable packaging
- 0.3: Tests work with tox. Supported platforms / versions frozen
- 0.5: Solid tests integrated with Travis or similar CI pipeline
- 0.9: Final API changes preparing for 1.0
- 1.0: API freeze
License
-------
``django-add-default-value`` is released under the Apache 2.0 License.
========================
Django Migration Operation that can be used to transfer a field's default value
to the database scheme.
[![PyPi](https://img.shields.io/pypi/v/django-add-default-value.svg?branch=master)](https://pypi.python.org/pypi/django-add-default-value/)
[![License](https://img.shields.io/github/license/3yourmind/django-add-default-value.svg)](./LICENSE)
[![Contributing](https://img.shields.io/badge/PR-welcome-green.svg)](https://github.com/3YOURMIND/django-add-default-value/pulls)
[![3yourminD-Careers](https://img.shields.io/badge/3YOURMIND-Hiring-brightgreen.svg)](https://www.3yourmind.com/career)
[![Stars](https://img.shields.io/github/stars/3YOURMIND/django-add-default-value.svg?style=social&label=Stars)](https://github.com/3YOURMIND/django-add-default-value/stargazers)
Dependencies
------------
* MySQL (or compatible)
* PostgreSQL
* Microsoft SQL Server
Installation
------------
`pip install django-add-default-value`
You can then use ``AddDefaultValue`` in your migration file to transfer the default
values to your database. Afterwards, it's just the usual ``./manage.py migrate``.
Usage
-----
Add this manually to a autogenerated Migration, that adds a new field::
AddDefaultValue(
model_name='my_model',
name='my_field',
value='my_default'
)
### Example
Given the following migration::
operations = [
migrations.AddField(
field=models.CharField(default='my_default', max_length=255),
model_name='my_model',
name='my_field',
),
]
Modify the migration to add a default value::
+from django_add_default_value import AddDefaultValue
+
operations = [
migrations.AddField(
field=models.CharField(default='my_default', max_length=255),
model_name='my_model',
name='my_field',
),
+ AddDefaultValue(
+ model_name='my_model',
+ name='my_field',
+ value='my_default'
+ )
]
If you check ``python manage.py sqlmigrate [app name] [migration]``,
you will see that the default value now gets set.
Contributing
------------
First of all, thank you very much for contributing to this project. Please base
your work on the ``master`` branch and target ``master`` in your pull request.
There are a few packages needed on the host system. For ubuntu the following
commands will install these
```text
apt-get install freetds-dev unixodbc-dev tdsodbc
```
Then add the following text to `/etc/odbcinst.ini`:
```ini
[FreeTDS]
Description=FreeTDS unixODBC Driver
Driver=/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup=/usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
```
To succesfully use the `dbshell` management command (very useful for debugging),
the client binaries for the respective database engines are needed.
Then install [pipenv](https://pipenv.readthedocs.io/en/latest/install/#installing-pipenv).
Edit the `Pipfile` to select your Django version and the accompanying MS-SQL
driver. Make sure you don't commit this change in any pull request - we always
set it to the oldest supported version.
Once you've updated the Pipfile, run `pipenv install --python 3 --dev`. You
should now have a working development environment as a virtualenv. To access it,
run `pipenv shell` or prefix commands with `pipenv run`. For more information
see the [pipenv documentation](https://pipenv.readthedocs.io/en/latest/basics/).
### Testing
Copy the relevant sample settings file in `test_project` to the file without
`.sample` in it. Adjust the values to match your environment (or match your
environment to the values).
You should now be able to run the tests using `tox`. Select your environment
when needed, using the `-e` command line flag. See
[Tox's excellent documentation](https://preview.tinyurl.com/y3faq6ab).
Roadmap
-------
- 0.1: Better and maintainable packaging
- 0.3: Tests work with tox. Supported platforms / versions frozen
- 0.5: Solid tests integrated with Travis or similar CI pipeline
- 0.9: Final API changes preparing for 1.0
- 1.0: API freeze
License
-------
``django-add-default-value`` is released under the Apache 2.0 License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-add-default-value-0.3.1.tar.gz
.
File metadata
- Download URL: django-add-default-value-0.3.1.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.7.2 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29298d779486ab374f8b43908d5ead1bcada470b959806928d442076b23e4886 |
|
MD5 | c3ed08e227b04fd05799130a5047379a |
|
BLAKE2b-256 | 5dc731ce222a2a2c53c849b897efcc6a2641a0a418a47055778106e498361ec0 |
File details
Details for the file django_add_default_value-0.3.1-py3-none-any.whl
.
File metadata
- Download URL: django_add_default_value-0.3.1-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.7.2 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3db3a1a1a2c6026270f294727b227a19a1a20bd1654c79fab23faee6a15523d7 |
|
MD5 | c335ca8919ccc6c17e52b071bab6861a |
|
BLAKE2b-256 | cff06b78e7d5bba14aacb6c22ca3516ea580abbbdc9e195f5055d73ded2e2af1 |