leve1031 发表于 2011-12-23 01:42

auto-generated Django model module.

Auto-generate the models
<p>Django comes with a utility called <a class="reference internal" href="https://docs.djangoproject.com/en/1.3/ref/django-admin/#django-admin-inspectdb"><span class="pre">inspectdb</span></a> that can create models
by introspecting an existing database. You can view the output by running this
command:</p>
<div class="highlight-bash"><div class="highlight">python manage.py inspectdb
</div>
</div>
<p>Save this as a file by using standard Unix output redirection:</p>
<div class="highlight-bash"><div class="highlight">python manage.py inspectdb &gt; models.py
</div>
</div>
<p>This feature is meant as a shortcut, not as definitive model generation. See the
<a class="reference internal" href="https://docs.djangoproject.com/en/1.3/ref/django-admin/#django-admin-inspectdb"><span class="pre">documentation</span> <span class="pre">of</span> <span class="pre">inspectdb</span></a> for more information.</p>
<p>Once you've cleaned up your models, name the file <span class="pre">models.py</span> and put it in
the Python package that holds your app. Then add the app to your
<a class="reference internal" href="https://docs.djangoproject.com/en/1.3/ref/settings/#std:setting-INSTALLED_APPS"><span class="pre">INSTALLED_APPS</span></a> setting.</p>

<div class="section" id="s-install-the-core-django-tables">
<span id="install-the-core-django-tables"></span>Install the core Django tables
<p>Next, run the <a class="reference internal" href="https://docs.djangoproject.com/en/1.3/ref/django-admin/#django-admin-syncdb"><span class="pre">syncdb</span></a> command to install any extra needed database
records such as admin permissions and content types:</p>
<div class="highlight-bash"><div class="highlight">python manage.py syncdb
</div>
</div>
</div>
页: [1]
查看完整版本: auto-generated Django model module.