{"title":"Daingneáin","version":"6.1","locale":"ga","docname":"topics/db/fixtures","url":"/ga/6.1/topics/db/fixtures/","canonical":"https://djangodocs.dev/ga/6.1/topics/db/fixtures/","summary":"Is bailiúchán comhaid é daingneamh ina bhfuil ábhar sraitheach an bhunachar sonraí.","html":"<span id=\"fixtures-explanation\"></span><h1>Daingneáin<a class=\"heading-anchor\" href=\"#fixtures\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>Is bailiúchán comhaid é <em>daingneamh</em> ina bhfuil ábhar sraitheach an bhunachar sonraí. Tá ainm uathúil ag gach daingneán, agus is féidir na comhaid a chuimsíonn an daingneán a dháileadh thar eolairí iolracha, in iolrfheidhmchláir.</p>\n<aside class=\"admonition admonition-seealso\" role=\"note\">\n<p class=\"admonition-title\">See also</p>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"/ga/6.1/howto/initial-data/\"><span class=\"doc\">Conas sonraí tosaigh a sholáthar do mhúnlaí</span></a></p></li>\n</ul>\n</aside>\n<section id=\"how-to-produce-a-fixture\">\n<h2>Conas daingneán a tháirgeadh<a class=\"heading-anchor\" href=\"#how-to-produce-a-fixture\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>&lt;dumpdata&gt;Is féidir daingneáin a ghiniúint trí:djadmin: <a href=\"#id1\"><span class=\"problematic\" id=\"id2\">`</span></a>manage.py dumpdata <a href=\"#id3\"><span class=\"problematic\" id=\"id4\">`</span></a>. Is féidir daingneáin saincheaptha a ghiniúint freisin trí úsáid a bhaint as go díreach: doc: <a href=\"#id5\"><span class=\"problematic\" id=\"id6\">`</span></a>uirlisí sraitheach' nó fiú trí iad a lámhscríobh &lt;/topics/serialization&gt;.</p>\n</section>\n<section id=\"how-to-use-a-fixture\">\n<h2>Conas daingneán a úsáid<a class=\"heading-anchor\" href=\"#how-to-use-a-fixture\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>&lt;topics-testing-fixtures&gt;Is féidir daingneáin a úsáid chun an bunachar sonraí a réamh-dhaonrú le sonraí le haghaidh: ref: <a href=\"#id1\"><span class=\"problematic\" id=\"id2\">`</span></a>tástálacha <a href=\"#id3\"><span class=\"problematic\" id=\"id4\">`</span></a>:</p>\n<div class=\"code-block\" data-language=\"python\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"k\">class</span> <span class=\"nc\">MyTestCase</span><span class=\"p\">(</span>TestCase<span class=\"p\">):</span>\n    fixtures <span class=\"o\">=</span> <span class=\"p\">[</span><span class=\"s2\">&quot;fixture-label&quot;</span><span class=\"p\">]</span>\n</code></pre></div>\n<p>nó chun roinnt: ref: sonraí tosaigh `a sholáthar ag baint úsáide as an ordú &lt;initial-data-via-fixtures&gt;:djadmin: `loaddata:</p>\n<div class=\"code-block\" data-language=\"shell\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Shell code\"><code>django-admin loaddata &lt;fixture label&gt;\n</code></pre></div>\n</section>\n<section id=\"how-fixtures-are-discovered\">\n<h2>Conas a aimsítear daingneáin<a class=\"heading-anchor\" href=\"#how-fixtures-are-discovered\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Déanfaidh Django cuardach sna háiteanna seo le haghaidh daingneáin:</p>\n<ol class=\"arabic simple\">\n<li><p>In eolaire <a href=\"#id1\"><span class=\"problematic\" id=\"id2\">``</span></a>daingneáin <a href=\"#id3\"><span class=\"problematic\" id=\"id4\">``</span></a>de gach feidhmchlár suiteáilte</p></li>\n<li><p>In aon eolaire atá liostaithe sa socrú: FIXTURE_DIRS</p></li>\n<li><p>Sa chosán litriúil a ainmníonn an daingneán</p></li>\n</ol>\n<p>Luchtálfaidh Django aon daingneáin agus gach daingneán a aimsíonn sé sna háiteanna seo a mheaitseálann leis na hainmneacha daingneáin Má tá síneadh comhad ag an daingneán ainmnithe, ní luchtálfar ach daingneáin den chineál sin. Mar shampla:</p>\n<div class=\"code-block\" data-language=\"shell\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Shell code\"><code>django-admin loaddata mydata.json\n</code></pre></div>\n<p>ní dhéanfaí ach daingneáin JSON ar a dtugtar mydata a luchtú. Caithfidh an síneadh daingneáin a fhreagraíonn d'ainm cláraithe a: ref: serializer &lt;serialization-formats&gt;`(m.sh., ``json` nó <code class=\"docutils literal notranslate\">xml</code>).</p>\n<p>Má fhágann tú na síntí, cuardóidh Django gach cineál daingneáin atá ar fáil le haghaidh daingneáin mheaitseála. Mar shampla:</p>\n<div class=\"code-block\" data-language=\"shell\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Shell code\"><code>django-admin loaddata mydata\n</code></pre></div>\n<p>lorgaíodh aon daingneán d'aon chineál daingneáin ar a dtugtar <code class=\"docutils literal notranslate\">mydata`. Dá mbeadh `mydata.json</code> i eolaire daingneáin, luchtálfaí an daingneán sin mar daingneán JSON.</p>\n<p>Is féidir comhpháirteanna eolaire a bheith san áireamh ar na daingneáin a Cuirfear na heolairí seo san áireamh sa chosán cuardaigh. Mar shampla:</p>\n<div class=\"code-block\" data-language=\"shell\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Shell code\"><code>django-admin loaddata foo/bar/mydata.json\n</code></pre></div>\n<p>chuardódh sé <code class=\"docutils literal notranslate\">&lt;app_label&gt;/fixtures/foo/bar/mydata.json</code> do gach feidhmchlár suiteáilte, <code class=\"docutils literal notranslate\">/foo/bar/mydata.json</code> do gach eolaire in:setting: FIXTURE_DIRS, agus an cosán litriúil <code class=\"docutils literal notranslate\">foo/bar &lt;dirname&gt;/mydata.json</code>.</p>\n<section id=\"fixtures-loading-order\">\n<h3>Ordú luchtaithe daingneo<a class=\"heading-anchor\" href=\"#fixtures-loading-order\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Is féidir daingneáin iolracha a shonrú san ionchur céanna. Mar shampla:</p>\n<div class=\"code-block\" data-language=\"shell\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Shell code\"><code>django-admin loaddata mammals birds insects\n</code></pre></div>\n<p>nó i rang cásanna tástála:</p>\n<div class=\"code-block\" data-language=\"python\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"k\">class</span> <span class=\"nc\">AnimalTestCase</span><span class=\"p\">(</span>TestCase<span class=\"p\">):</span>\n    fixtures <span class=\"o\">=</span> <span class=\"p\">[</span><span class=\"s2\">&quot;mammals&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;birds&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;insects&quot;</span><span class=\"p\">]</span>\n</code></pre></div>\n<p>Leanann an t-ord ina luchtaítear daingneáin an t-ord ina bhfuil siad liostaithe, cibé acu agus an t-ordú bainistíochta á úsáid agat nó nuair a liostaítear iad i rang an cháis tástála mar a thaispeántar thuas.</p>\n<p>Sna samplaí seo, luchtálfar na daingneáin go léir darb ainm <code class=\"docutils literal notranslate\">mamaí ``ó gach feidhmchlár (san ord ina sainmhínítear feidhmchláir in:setting: `INSTALLED_APPS`) ar dtús. Ina dhiaidh sin, luchtálfar na daingneáin ``éan</code> go léir, agus ina dhiaidh sin beidh na daingneáin <a href=\"#id1\"><span class=\"problematic\" id=\"id2\">``</span></a>feithidí <a href=\"#id3\"><span class=\"problematic\" id=\"id4\">``</span></a>go léir ina dhiaidh sin.</p>\n<p>Bí ar an eolas má thacaíonn cúltaca an bhunachar sonraí le srianta leibhéal sraithe, déanfar na srianta seo a sheiceáil ag deireadh an idirbheart. D'fhéadfadh earráid ualaigh a bheith mar thoradh ar aon chaidrimh ar fud daingneáin mura dtacaíonn cumraíocht an bhunachar sonraí le seiceáil srianta iarchurtha (féach do na doiciméid <a class=\"reference external\" href=\"https://dev.mysql.com/doc/refman/en/constraint-foreign-key.html\">MySQL</a> mar shampla).</p>\n</section>\n</section>\n<section id=\"how-fixtures-are-saved-to-the-database\">\n<h2>Conas a shábháil daingneáin sa bhunachar sonraí<a class=\"heading-anchor\" href=\"#how-fixtures-are-saved-to-the-database\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>When fixture files are processed, the data is saved to the database as is.\nModel defined <a class=\"reference internal\" href=\"/ga/6.1/ref/models/instances/#django.db.models.Model.save\" title=\"django.db.models.Model.save\"><code class=\"xref py py-meth docutils literal notranslate\">save()</code></a> methods are not called, and\nany <a class=\"reference internal\" href=\"/ga/6.1/ref/signals/#django.db.models.signals.pre_save\" title=\"django.db.models.signals.pre_save\"><code class=\"xref py py-data docutils literal notranslate\">pre_save</code></a>,\n<a class=\"reference internal\" href=\"/ga/6.1/ref/signals/#django.db.models.signals.post_save\" title=\"django.db.models.signals.post_save\"><code class=\"xref py py-data docutils literal notranslate\">post_save</code></a>, or\n<a class=\"reference internal\" href=\"/ga/6.1/ref/signals/#django.db.models.signals.m2m_changed\" title=\"django.db.models.signals.m2m_changed\"><code class=\"xref py py-data docutils literal notranslate\">m2m_changed</code></a> signals will be called with\n<code class=\"docutils literal notranslate\">raw=True</code> since the instance only contains attributes that are local to the\nmodel. You may, for example, want to disable handlers that access\nrelated fields that aren't present during fixture loading and would otherwise\nraise an exception:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.db.models.signals</span> <span class=\"kn\">import</span> post_save\n<span class=\"kn\">from</span> <span class=\"nn\">.models</span> <span class=\"kn\">import</span> MyModel\n\n\n<span class=\"k\">def</span> <span class=\"nf\">my_handler</span><span class=\"p\">(</span><span class=\"o\">**</span>kwargs<span class=\"p\">):</span>\n    <span class=\"c1\"># disable the handler during fixture loading</span>\n    <span class=\"k\">if</span> kwargs<span class=\"p\">[</span><span class=\"s2\">&quot;raw&quot;</span><span class=\"p\">]:</span>\n        <span class=\"k\">return</span>\n    <span class=\"o\">...</span>\n\n\npost_save<span class=\"o\">.</span>connect<span class=\"p\">(</span>my_handler<span class=\"p\">,</span> sender<span class=\"o\">=</span>MyModel<span class=\"p\">)</span>\n</code></pre></div>\n<p>D'fhéadfá maisitheoir a scríobh freisin chun an loighic seo a chumhdú:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">functools</span> <span class=\"kn\">import</span> wraps\n\n\n<span class=\"k\">def</span> <span class=\"nf\">disable_for_loaddata</span><span class=\"p\">(</span>signal_handler<span class=\"p\">):</span>\n    <span class=\"sd\">&quot;&quot;&quot;</span>\n<span class=\"sd\">    Decorator that turns off signal handlers when loading fixture data.</span>\n<span class=\"sd\">    &quot;&quot;&quot;</span>\n\n    <span class=\"nd\">@wraps</span><span class=\"p\">(</span>signal_handler<span class=\"p\">)</span>\n    <span class=\"k\">def</span> <span class=\"nf\">wrapper</span><span class=\"p\">(</span><span class=\"o\">*</span>args<span class=\"p\">,</span> <span class=\"o\">**</span>kwargs<span class=\"p\">):</span>\n        <span class=\"k\">if</span> kwargs<span class=\"p\">[</span><span class=\"s2\">&quot;raw&quot;</span><span class=\"p\">]:</span>\n            <span class=\"k\">return</span>\n        signal_handler<span class=\"p\">(</span><span class=\"o\">*</span>args<span class=\"p\">,</span> <span class=\"o\">**</span>kwargs<span class=\"p\">)</span>\n\n    <span class=\"k\">return</span> wrapper\n\n\n<span class=\"nd\">@disable_for_loaddata</span>\n<span class=\"k\">def</span> <span class=\"nf\">my_handler</span><span class=\"p\">(</span><span class=\"o\">**</span>kwargs<span class=\"p\">):</span> <span class=\"o\">...</span>\n</code></pre></div>\n<p>Bí ar an eolas go ndéanfaidh an loighic seo na comharthaí a dhíchumasú aon uair a dhíshealtar daingneáin, ní hamháin le linn: djadmin: loaddata.</p>\n<aside class=\"version-note version-changed\" data-version=\"6.1\" role=\"note\">\n<p class=\"version-note-title\">Changed in Django 6.1</p><p>The <code class=\"docutils literal notranslate\">raw</code> argument was added to <code class=\"docutils literal notranslate\">m2m_changed</code> signals.</p>\n</aside>\n</section>\n<section id=\"compressed-fixtures\">\n<h2>Daingneáin chomhbh<a class=\"heading-anchor\" href=\"#compressed-fixtures\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Féadfar daingneáin a chomhbhrúite i bhformáid <code class=\"docutils literal notranslate\">zip</code>, gz`, bz2`, lz`, nó <code class=\"docutils literal notranslate\">xz</code>. Mar shampla:</p>\n<div class=\"code-block\" data-language=\"shell\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Shell code\"><code>django-admin loaddata mydata.json\n</code></pre></div>\n<p>lorg aon cheann de mydata.json`, mydata.json.zip`, mydata.json.gz`, mydata.json.gz`, mydata.json.xz`, mydata.json.lz`, nó <code class=\"docutils literal notranslate\">mydata.json.xz</code>. Úsáidtear an chéad chomhad atá laistigh de chartlann comhbhrúite.</p>\n<p>Tabhair faoi deara má aimsítear dhá daingneán leis an ainm céanna ach cineál daingneáin difriúil (mar shampla, má aimsíodh <code class=\"docutils literal notranslate\">mydata.json</code> agus mydata.xml.gz` san eolaire daingneáin chéanna), cuirfear deireadh leis an suiteáil daingneáin, agus bainfear aon sonraí suiteáilte sa ghlao chu:djadmin: loaddata ón mbunachar sonraí.</p>\n<aside class=\"admonition-mysql-with-myisam-and-fixtures admonition\" role=\"note\">\n<p class=\"admonition-title\">MySQL le MyISAM agus daingneáin</p>\n<p>Ní thacaíonn inneall stórála MyISAM MySQL le hidirbhearta nó srianta, mar sin má úsáideann tú MyISAM, ní gheobhaidh tú bailíochtú sonraí daingneáin, ná rolladh siar má aimsítear comhad idirbheart iolracha.</p>\n</aside>\n</section>\n<section id=\"database-specific-fixtures\">\n<h2>Daingneáin sonrach le bunachar sonraí<a class=\"heading-anchor\" href=\"#database-specific-fixtures\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Má tá tú i socrú ilbhunachar sonraí, b'fhéidir go mbeadh sonraí daingneáin agat ar mhaith leat a luchtú ar bhunachar sonraí amháin, ach ní ar bhunachar sonraí eile. Sa chás seo, is féidir leat aitheantóir bunachar sonraí a chur isteach in ainmneacha do daingneáin.</p>\n<p>Mar shampla, má tá bunachar sonraí <code class=\"docutils literal notranslate\">users</code> sainithe ag do shuíomh: DATABASES, ainmnigh an daingneán <code class=\"docutils literal notranslate\">mydata.users.json</code> nó <code class=\"docutils literal notranslate\">mydata.users.json.gz</code> agus ní luchtálfar an daingneán ach nuair a shonraíonn tú gur mhaith leat sonraí a luchtú isteach sa bhunachar sonraí <code class=\"docutils literal notranslate\">users</code>.</p>\n</section>","rootId":"fixtures","toc":[{"title":"Conas daingneán a tháirgeadh","anchor":"how-to-produce-a-fixture","children":[]},{"title":"Conas daingneán a úsáid","anchor":"how-to-use-a-fixture","children":[]},{"title":"Conas a aimsítear daingneáin","anchor":"how-fixtures-are-discovered","children":[{"title":"Ordú luchtaithe daingneo","anchor":"fixtures-loading-order","children":[]}]},{"title":"Conas a shábháil daingneáin sa bhunachar sonraí","anchor":"how-fixtures-are-saved-to-the-database","children":[]},{"title":"Daingneáin chomhbh","anchor":"compressed-fixtures","children":[]},{"title":"Daingneáin sonrach le bunachar sonraí","anchor":"database-specific-fixtures","children":[]}],"breadcrumbs":[{"docname":"topics/index","title":"Using Django","url":"/ga/6.1/topics/"},{"docname":"topics/db/index","title":"Samhlacha agus bunachair sonraí","url":"/ga/6.1/topics/db/"}],"prev":{"docname":"topics/db/instrumentation","title":"Ionstraimíocht bunachar sonraí","url":"/ga/6.1/topics/db/instrumentation/"},"next":{"docname":"topics/db/examples/index","title":"Samplaí d'úsáid API caidrimh samhail","url":"/ga/6.1/topics/db/examples/"},"formats":{"html":"/ga/6.1/topics/db/fixtures/","markdown":"/ga/6.1/topics/db/fixtures.md","json":"/ga/6.1/topics/db/fixtures.json"},"source":"https://github.com/django/django/blob/stable/6.1.x/docs/topics/db/fixtures.txt","official":"https://docs.djangoproject.com/ga/6.1/topics/db/fixtures/","inVersions":["6.1","6.0","5.2"],"inLocales":["en","sv","zh-hans","ga","fr","ja","id","it","pt-br","ko","es","el","pl"]}