how to disable migration from one model of an app in django - django-models

I have an application which is using 2 database, 1 is default another is custom. So 2 of my model are using default database, else are using custom database. i do not want to migrate custom database model while running 'make migrations' command. please help it out.

You can selectively disable migration for one or more Django-Models by setting managed = False in Django Model Meta options.
from django.db import models
class LegacyModel(models.Model):
class Meta:
managed = False

It's worth mentioning that although the managed flag is set to False a migration for the model will still be created but no sql creation script.
The sql of a migration ca be check using manage.py sqlmigrate appname migration

Options.managed Defaults to True, meaning Django will create the
appropriate database tables in migrate or as part of migrations and
remove them as part of a flush management command. That is, Django
manages the database tables’ lifecycles.
If False, no database table creation or deletion operations will be
performed for this model. This is useful if the model represents an
existing table or a database view that has been created by some other
means. This is the only difference when managed=False. All other
aspects of model handling are exactly the same as normal.
From the docs
class SomeModel(models.Model):
class Meta:
managed = False

Related

Switch from using one database to having one for auth and one for everything else

Within my Django app I currently only have one DB, under settings it is default. What I want to do is port over all of the Auth tables created by Django to a separate database, Ill say SiteAuth for now.
I have copied all of the auth tables over to the SiteAuth db, but I am not sure how to integrate those changes within the site. I know I am going to have to add another db the databases section of settings, But I am not sure how to do the migrations, or how to specify which database I want to query.
How would I do the migrations? how would I specify which database I want to query? how would my models.py change?
Thanks for all the help!
you need to write a router. Check this:
https://docs.djangoproject.com/en/2.2/topics/db/multi-db/
I would recommend to keep the auth in the default db, and move the other stuff in the new one. On the other questions the docs are very descriptive, but to summarize you need to add stuff to the Meta class of your models.

TeamCity LDAP Synchronization not working for VCS properties

I have configured TeamCity (8.1.4) for LDAP logins and it works as advertised including synchronization of displayname and email. But I have a problem with synchronization of VCS properties.
New users are being created (when they first log in) without their display name or email address being populated. This is remedied when the sync happens, so I know the sync works for those properties.
I need the "Default for all of VCS roots" property filled out properly as well though. This is required so that people can be matched to their check-ins (it's not happening at the moment) so they can be emailed when they break the tests.
The "Default for all of VCS roots" property is simply being populated as username, but I need it to be DOMAIN\username.
My settings:
java.naming.provider.url=ldap://my.domaincontroller.com:389/DC=mydomain,DC=local
java.naming.security.principal=monkey
java.naming.security.credentials=bubbles
teamcity.users.base=OU=group2,OU=Users
teamcity.users.login.filter=(sAMAccountName=$capturedLogin$)
teamcity.users.username=sAMAccountName
teamcity.auth.loginFilter=.*
teamcity.options.users.synchronize=true
teamcity.users.filter=(objectClass=user)
teamcity.options.groups.synchronize=false
teamcity.options.createUsers=false
teamcity.options.deleteUsers=false
teamcity.options.syncTimeout = 3600000
teamcity.groups.property.member=member
teamcity.users.property.displayName=displayName
teamcity.users.property.email=mail
teamcity.users.property.plugin\:vcs\:anyVcs:anyVcsRoot=mydomain\\$sAMAccountName$
You can play around with the settings for LDAP to achieve this but we ran into some issues when we set this up on our projects. We had more than one type of VCS repo and when we started to move to Git, our repository just did not store usernames in DOMAIN//username syntax.
A better way would be to update the user tables in teamcity database to set the default userid for all TFS based roots to DOMAIn/username. This is the syntax
insert into user_property
values(<user_id>,'plugin:vcs:jetbrains.**tfs**:anyVcsRoot','DOMAIN//username')

How can I paginate data from different database's table in cakephp?

I have two database users and magento.
magento is reside at remote machine in LAN.
and users is reside at my local machine.
connection between them and fetching data from that magento database is working fine
but I want to do pagination on magento's table data.
simple displaying it is done, but for pagination we require model name, and how can i have model of other database??
// in controller action
$this->Vendor->changeDataSource('vsdatabase');
if($this->changeDbSource('vsdatabase'))
{
$magento_data = $this->Vendor->query("SELECT * from admin_user");
$this->set('products',$magento_data);
}
and changeDataSource($newdb) is defined in model file
and changeDbSource($database='default') in controller
so how can I solve my problem with pagination?
I have completed fetching data without pagination.
or any other option to do this?
Thanks,
You're going about this the wrong way..
You should create a new database configuration for the external database, call it say.. $vendor_db in app/config/database.php
http://book.cakephp.org/1.3/en/view/922/Database-Configuration
Then you need a model for your new connection. Tell the model what database connection to use with $useDBConfig:
class Vendor extends AppModel {
var $useDbConfig = 'vendor_db';
}
http://book.cakephp.org/1.3/en/view/1058/useDbConfig
This way, in your Vendors controller you can make database calls using standard cakePHP functions, including paginate.
$this->paginate('Vendor')
cakePHP model functions should almost always preclude you from writing your own queries. Generally speaking, if you think you have to write a query, you're probably doing something wrong.

Django admin interface and added tables

I'm using Django with sqlite to make a web app and ran into a little issue.
I created a table under models file called deletedOrder, gave it variables etc., and then ran manage.py syncdb. This created the table in my database and I was able to add data to the database table and read the data back out, however this added table is not showing up on the Django admin interface.
Is there something else that I have to do to get this to be in the admin page?
You need to register your models to make them show up in the admin as documented here.

How to configure Django to reinitialize and populate the entire database on startup?

Let's assume that you are working at the first version of a new Django application and you are keep adding changing the models.
Being a data-driven application you are mostly working to customize django admin.
In this case syncdb is not too useful because it will fail to update models. South was interesting but it does not make too much sense when you are working at the first version.
Deleting database and reinitializing it require several commands and also you manually entering the new admin account.
How do you propose to set your development environment so you can:
auto-restart django server when files changed
auto-reinitialize database when django is restarted
As a result, I expect to be able to add a new attribute to a model, switch to the browser and refresh the admin page and see the new attribute.
Providing initial data for models
It’s sometimes useful to pre-populate your database with hard-coded data when you’re first setting up an app. There’s a couple of ways you can have Django automatically create this data: you can provide initial data via fixtures, or you can provide initial data as SQL.
In general, using a fixture is a cleaner method since it’s database-agnostic, but initial SQL is also quite a bit more flexible.
http://docs.djangoproject.com/en/dev/howto/initial-data/

Resources