> For the complete documentation index, see [llms.txt](https://docs.novel.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.novel.dev/novel-server/migrations.md).

# Migrations

Migrations in Novel API are handled by Knex.js

{% embed url="<https://knexjs.org/guide/migrations.html>" %}

The big difference with Novel is that migrations are auto executed during runtime. This means any changes to the migrations are applied immediately.

During development time, Novel auto-generates Models and the accompanying validation and schema files to be registered within the server as well as made available to you for import.

You can check how models work below

{% embed url="<https://docs.novel.dev/novel-server/models>" %}

## Best Practices

Start by following the tutorial below

{% embed url="<https://docs.novel.dev/guides/knowledge-base/database/creating-a-table>" %}

1. Name your table in plural form.
2. Be careful of your indices and primary keys. Maybe a composite primary key is more useful.
3. There is no need to add a maximum length to strings.
4. Make use of `.references('table_name.foreign_key')` when defining relationships.
5. Make use of timestamps for boolean fields.
6. Make sure you add references to organization ID or account ID where needed.
7. Avoid using UUID v4s for your Primary Keys. Consider UUID v1/v7, ULID, or normal Big Int.

## Prototyping

When prototyping, you may perform trial-and-error on tables and columns.&#x20;

{% hint style="warning" %}
At 2025.1.0, there is no automatic way to temporarily try your database changes without data loss.&#x20;
{% endhint %}

If you need to prototype your database tables temporarily, you will need to:

1. Delete the migration file row in the `_migrations` table in your database
2. Run `knex migrate:rollback` to rollback the change that was made to the database.
3. Run the migration again with your changes.

## Changelog

* 2024-12-20 - Initial Documentation
