Meta class reference

This document covers features of the Meta class. The meta class defines model specific settings and is used as an inner class in the model:

from data_migrator import models

class SampleModel(models.Model):
  a = models.IntField(pos=1)

  class Meta:
    drop_if_none = True

Every model can have its own meta class to define model specific options.

Note

Technically, Meta is just a container and forwarded to Options

class data_migrator.models.options.Options(cls, meta, fields)
__init__(cls, meta, fields)

Options is the Model Meta data container

The Options class is the true meta data container and parser for a Model. It contains all flag and fields references for model handling. Use these flags in the Meta sub class of a Model.

Parameters:
  • cls – the Model this Options object is refering too
  • meta – the reference to a Meta class
  • fields (list) – list of all field definitions
drop_if_none

list – names of the columns to check for None, Is a list of field names as defined. If set data-migrator will check if fields are not None and drop if one of the columns is.

drop_non_unique

boolean – If True, data-migrator will drop values if the column uniqueness check fails (after parsing). Default is False.

Any field can be defined as a unique column. Any field set so, is checked after scanning and just before save-ing.

emitter

BaseEmitter – If set, data-migrator will use this emitter instead of the default emitter.

fail_non_unique

boolean – If True, data-migrator will fail as a whole if the column uniqueness check fails (after parsing). Default is False.

Any field can be defined as a unique column. Any field set so, is checked after scanning and just before save-ing.

fail_non_validated

boolean – If True, data-migrator will fail as a whole if the column validation check fails (after parsing). Default is False.

Any field can have its own validator, this is a rough method to prevent bad data from being transformed and loaded.

file_name

string – If set, data-migrator will use this as file_name for the emitter instead of the default filename based on model_name.

table_name

string – If set, data-migrator will use this as table_name for the emitter instead of the default table_name based on model_name.

prefix

string – If set, data-migrator will use this list of statements as a preamble in the generation of the output statements.

By default an emitter uses this to clear the old state.

remark

string – If set, data-migrator will use this as the remark attribute in the Model, default=’remark’. Use this for example if you have a remark field in your model and need to free the keyword.

strict

boolean – If True, data-migrator will be strict on the model and does not allow values outside of the definitions. Default is None.

manager

BaseManager – If set, data-migrator will use this as the manager for this model.

This is useful if the transform method needs to be overridden.

Raises:DefinitionException – raised if any of the defintions is not to spec.

Note

Note that only NullXXXFields actually can be None after scanning and parsing. Non Null fields are set to their default value.