Create Tables

Relational Data Model

As already mentioned in Create a schema, all data in DataJoint are represented in the form of tables residing in databases on the database server. On the client side, in Python and MATLAB, each table has its own DataJoint class, which defines the table and manipulates its data.

Data Tiers

The table class must inherit from one of the following superclasses: dj.Lookup, dj.Manual, dj.Imported, dj.Computed, or dj.Part to indicate its data tier. See Data Tiers and Part Tables.

Defining a table

matlab MATLAB

DataJoint for MATLAB provides the interactive script for creating a new table. It will prompt to enter the new table’s class name in the form package.ClassName. This will create the file +package/ClassName.m.

For example, define the table experiment.Person

Enter <package>.<ClassName>: experiment.Person

Choose table tier:
 (L/M/I/C/P) > M

This will create the file +experiment/Person.m with the following contents:

# my newest table
# add primary key here
# add additional attributes

classdef Person < dj.Manual
end adds a little bit of convenience while some users may create the classes from scratch manually.

The important part is that the class inherits from the DataJoint class corresponding to the correct [data tier](Data tiers): dj.Lookup, dj.Manual, dj.Imported or dj.Computed.

The most important part of the table definition is the comment preceding the classdef. DataJoint will parse this comment to define the table.

The class will become usable after you edit this comment as described in Table Definition.

python Python

To define a DataJoint table in Python: 1. Define a class inheriting from the appropriate DataJoint class: dj.Lookup, dj.Manual, dj.Imported or dj.Computed. 2. Decorate the class with the schema object (See Create a schema) 3. Define the class property definition to define the table heading.

For example, the following code defines the table Person:

import datajoint as dj
schema = dj.schema('alice_experiment', locals())

class Person(dj.Manual):
    definition = '''
    # table definition goes here

The class will become usable after you edit the definition property as described in Table Definition.

Valid class names

Note that in both MATLAB and Python, the class names must follow the CamelCase compound word notation: * start with a capital letter and * contain only alphanumerical characters (no underscores).


Valid class names

TwoPhotonScan, Scan2P, Ephys, MembraneVoltage

Invalid class names

Two_photon_Scan, twoPhotonScan, 2PhotonScan, membranePotential, membrane_potential