---
title: "모델의 초기 데이터 제공하기."
version: 3.0
locale: ko
source: https://docs.djangoproject.com/ko/3.0/howto/initial-data/
canonical: https://djangodocs.dev/ko/3.0/howto/initial-data/
---
# 모델의 초기 데이터 제공하기.

It’s sometimes useful to pre-populate your database with hard-coded data when
you’re first setting up an app. You can provide initial data with migrations or
fixtures.

## 마이그레이션으로 초기 데이터 제공하기.

If you want to automatically load initial data for an app, create a
[data migration](/ko/3.0/topics/migrations/#data-migrations). Migrations are run when setting up the
test database, so the data will be available there, subject to [some
limitations](/ko/3.0/topics/testing/overview/#test-case-serialized-rollback).

## Providing data with fixtures

You can also provide data using fixtures, however, this data isn’t loaded
automatically, except if you use [`TransactionTestCase.fixtures`](/ko/3.0/topics/testing/tools/#django.test.TransactionTestCase.fixtures).

A fixture is a collection of data that Django knows how to import into a
database. The most straightforward way of creating a fixture if you’ve already
got some data is to use the [`manage.py dumpdata`](/ko/3.0/ref/django-admin/#django-admin-dumpdata) command.
Or, you can write fixtures by hand; fixtures can be written as JSON, XML or YAML
(with [PyYAML](https://pyyaml.org/) installed) documents. The [serialization documentation](/ko/3.0/topics/serialization/) has more details about each of these supported
[serialization formats](/ko/3.0/topics/serialization/#serialization-formats).

As an example, though, here’s what a fixture for a `Person` model might look
like in JSON:

```js
[
  {
    "model": "myapp.person",
    "pk": 1,
    "fields": {
      "first_name": "John",
      "last_name": "Lennon"
    }
  },
  {
    "model": "myapp.person",
    "pk": 2,
    "fields": {
      "first_name": "Paul",
      "last_name": "McCartney"
    }
  }
]
```

그리고 YAML로 된 동일한 fixture 가 있습니다.

```yaml
- model: myapp.person
  pk: 1
  fields:
    first_name: John
    last_name: Lennon
- model: myapp.person
  pk: 2
  fields:
    first_name: Paul
    last_name: McCartney
```

You’ll store this data in a `fixtures` directory inside your app.

You can load data by calling [`manage.py loaddata`](/ko/3.0/ref/django-admin/#django-admin-loaddata)
`<fixturename>`, where `<fixturename>` is the name of the fixture file
you’ve created. Each time you run [`loaddata`](/ko/3.0/ref/django-admin/#django-admin-loaddata), the data will be read
from the fixture and re-loaded into the database. Note this means that if you
change one of the rows created by a fixture and then run [`loaddata`](/ko/3.0/ref/django-admin/#django-admin-loaddata)
again, you’ll wipe out any changes you’ve made.

### Where Django finds fixture files

By default, Django looks in the `fixtures` directory inside each app for
fixtures. You can set the [`FIXTURE_DIRS`](/ko/3.0/ref/settings/#std-setting-FIXTURE_DIRS) setting to a list of
additional directories where Django should look.

When running [`manage.py loaddata`](/ko/3.0/ref/django-admin/#django-admin-loaddata), you can also
specify a path to a fixture file, which overrides searching the usual
directories.

> **See also**
>
> Fixtures are also used by the [testing framework](/ko/3.0/topics/testing/tools/#topics-testing-fixtures) to help set up a consistent test environment.
