I can't get automigrate and autoupdate to work.
I created my project, datasource and model. All looks good, but I can't get automigrate to work. If I go to my SQL Server and create the table/schema then all the GET/POST methods work fine.
I went to the server/boot directory. there are currently two files in there authentication and root.
I created a new file called automigrate.js
'use strict';
module.exports = function (app) {
app.dataSources.mysql.automigrate();
console.log("Performed automigration.");
}
When I run it I get an error :
C:\Users\ajmal\loopback\telematics\server\server.js:31 if (err) throw err; ^
TypeError: Cannot read property 'automigrate' of undefined
at Object.module.exports [as func] (C:\Users\ajmal\loopback\telematics\server\boot\automigrate.js:9:26)
at C:\Users\ajmal\loopback\telematics\node_modules\loopback-boot\lib\executor.js:316:22
You can use grunt-loopback-auto module or build your own by following the document at https://loopback.io/doc/en/lb3/Creating-a-database-schema-from-models.html#auto-update
Notes:
automigrate will drop and re-create the tables. Therefore, data will be lost. It's terrible on production.
autoupdate calculates the difference between the LoopBack model and the database table definition and alters the table accordingly.
So, we should use autoupdate in almost cases.
Related
I am creating a hybrid app by telerik app builder in visual studio. I am not able to access sqlite db which is created externally. But I can access the db which is created at run time. I referred some sites, those solutions are not worked for me. The following code will create db and access it while run time
var app = {};
app.db = null;
app.openDb = function () {
var dbName = "Test.sqlite";
//DB creation for Simulator
if (window.navigator.simulator === true) {
app.db = window.openDatabase(dbName, "1.0", "Test Database", 1073741824);
console.log("Database Created!");
}
//DB creation for devices
else {
app.db = window.sqlitePlugin.openDatabase(dbName);
console.log("Database Accessed!");
}
}
I want to access the database which is present in the data folder. Please refer the image.
I tried to place the db in www folder and try to access it by the following code
app.db = window.sqlitePlugin.openDatabase({name: "Test.db", createFromLocation: 1});
It will give the following error
Uncaught TypeError: Cannot read property 'openDatabase' of undefined
So, how can I access the externally created sqlite db?
I included the following scripts in the project
<script src="js/jquery-2.1.0.min.js"></script>
<script src="js/angular.min.js"></script>
<script src="js/ng-cordova.min.js"></script>
It looks like your issue is that window.sqlitePlugin is undefined. Are you sure the plugin is properly installed? Also, you must wait until the deviceReady event before using window.sqlitePlugin.
I'm building an SPA in AngularJS served by a Laravel (5.1) backend. Of late I've been encountering an annoying error, a server 500 or code 0 error which is abit hard to explain how it comes but let me try to may be someone will understand the dental formula of my problem.
When i start my AngularJS controller, I make several server calls (via independent $http calls from services) to retrieve information i might later need in the controller. For example,
Functions.getGrades()
.then(function(response)
{
$scope.grades = response.data;
});
Subjects.offered()
.then(function(response)
{
$scope.subjects = response.data;
});
Later on i pass these variables (grades or subjects) to a service where they are used for processing. However, these functions are randomly returning code 500 server errors after they run, and sometimes returning status code 0 after running. This happens in a random way and it is hard for me to point out the circumstances leading to their popping up. This leaves me with frequent empty Laravel-ised error screens like the ones shown below.
Anyone reading my mind?
Ok, after a suggestion given in a comment above that I check my Laravel log files (located in storage/logs/laravel.log- Laravel 5.1), i found out that the main error most of these times was this one: 'PDOException' with message 'SQLSTATE[HY000] [1044] Access denied for user ''#'localhost' to database 'forge'' in ..., plus another one that paraphrased something like No valid encrypter found. These were the key opener.
On reading another SO thread here, it said in part:
I solved, sometimes laravel not read APP_KEY in .ENV. And returns a value "SomeRandomString" (default is defined in config / app.php), and have the error "key length is invalid", so the solution is to copy the value of APP_KEY, to the value 'key 'in config / app.php, that's all! I solved!
That was exactly the issue! When loading the DB params from the .env to config/database.php, Laravel was sometimes unable to read the environment variables and went for the fallback default fallback options (forge for DB name and username and SomeRandomString for the APP_KEY). So, to solve this i just did as advised: copied the APP_KEY in .env to the config/app.php and edited the default DB parameters to the actual DB name and username/password I'm using. Just that and i was free from pollution. Hope someone finds this helpful.
I'm working on an application using Play and Slick. This app requires access to (at least) two databases and this is working fine when one is defined as default and other is named. Eg.,
db.default.driver = "com.mysql.jdbc.Driver"
db.default.url = "jdbc:mysql://localhost:3306/db1"
db.db2.driver = "com.mysql.jdbc.Driver"
db.db2.url = "jdbc:mysql://localhost:3306/db2"
I can then happily access each db as follows
DB.withSession { implicit session => ??? }
DB("db2").withSession { implicit session => ??? }
However, this doesn't really make sense as there is no reason DB1 should be the default. The DBs contain different types of data, neither is the default, both are important. What I would like is:
db.db1.driver = "com.mysql.jdbc.Driver"
db.db1.url = "jdbc:mysql://localhost:3306/db1"
db.db2.driver = "com.mysql.jdbc.Driver"
db.db2.url = "jdbc:mysql://localhost:3306/db2"
Play-scala barfs at this thought. It needs a default db driver and URL and it needs to be able to connect to it.
Anyone know anyway to change this behaviour or to trick play into thinking it has a default?
UPDATE
To be clear, I've greped my code to ensure that I'm not using DB.withSession anywhere. That is, every time I create a session I use DB("db1").withSession or DB("db2").withSession. However, when I run my test, I still get an exception:
Caused by: Configuration error: Configuration error[Slick error : jdbc driver not defined in application.conf for db.default.driver key]
Something somewhere is trying to load the default config.
Default is just a name, with some convenience functions (withSession and withTransaction without name), so, no you do not need to have a default connection if it does not fit your project.
I'm trying to create a search form view based on the following example of Sencha :
http://try.sencha.com/touch/2.0.0/examples/list-search/viewer.html
I made a few changes just not to create the view by code but export it in a view.
To set up the store, i use this in the config :
store: Preconisations.app.getStoreAdherents(),
where Preconisations is my project name and getStoreAdherents the function set in the app.js:
getStoreAdherents: function () {
if (!this.storeAdherents) {
var gestionAdherent = new DAL_Adherent(); // custom classes
var tc = gestionAdherent.GetAll(); // and functions which returns a json string with data
this.storeAdherents = Ext.create('Ext.data.Store', {
model: "Preconisations.model.ADHERENT",
data: tc,
sorters: 'nom',
groupField: 'code'
});
}
return this.storeAdherents;
}
Now, everything works fine but when i make the testing or the production build, i've got this error :
Uncaught TypeError: Cannot call method 'getStoreAdherents' of undefined
at the store definition...
Maybe, there's a better way to set up the store by code but i can't understand why it's working in developpement and not with the production or testing build...
Is anyone had this problem ? Or how do you set up dynamically a store with a function ?
Thanks... I'm banging my head on the wall on this one...
It is clear that you have a build dependency issue in Ext Build. In the code snippet posted, there is a chance that you missed to add "Preconisations.model.ADHERENT" to a class path. If so, please add the following to your app.js
requires: ["Preconisations.model.ADHERENT"]
If the issue persist, Please do the following diagnostics :
Run your app (development mode) in Google Chrome with the Console open; Look for warnings that states a particular class is being synchronously loaded and add requires statement for those classes.
In fact i think there's a bug in setting a store dynamically in the config.
I found this workaround which work in developpement and in build production :
I don't specify a store : xxxx in the view.
Instead, in a controller i put this code in the launch function :
this.getMainView().setStore(this.getStoreAdherents());
where getMainView is a reference to my view.
That's all !
I've been struggling with the deployment of our force.com application code that has, up to now, been developed in a single development org I'll call DevOrg.
What I want to do is transfer the DevOrg objects, code, pages, etc from DevOrg to a sandbox in a new org (NewOrg) that I have created. NewOrg and its sandbox are devoid of any code/objects related to the application. I've used the migration tool to retrieve the code from DevOrg and have fashioned the package.xml in various ways to get the code to deploy the NewOrg sandbox, but I keep getting tons of errors, for example:
[sf:deploy] SomeClass: line 1014, column 95: Dependent class is invalid and needs recompilation:
[sf:deploy] SomceClass2: line 475, column 37: Dependent class is invalid and needs recompilation:
I went into the Eclipse IDE and checked out the project from DevOrg, exported the project and imported it to a project pointed to NewOrg's sandbox. I thought perhaps this would give me hints about a working package.xml since I can work in the DevOrg project in the Eclipse IDE without any problems/errors.
But instead I found the same errors in the NewOrg sandbox project when loaded within the IDE. So I tried making adding a space to the dependent class and saving it to the NewOrg sandbox and I received an sObject error like this:
Save error:
sObject type 'SomeClass__c' is not supported.
If you are attempting to use a custom object, be sure to append the '__c' after the entity name.
Please reference your WSDL or the describe call for the appropriate names.
Thinking this must be because the objects haven't been deployed to NewOrg's sandbox, I attempted to the deploy only the objects in the project. That too failed. This time with errors like this:
Save error:
Appointment_Type_Form__c.Form__c : referenceTo value of 'Form_Template__c'
does not resolve to a valid sObject type Appointment_Type_Form__c.object
Save error:
Form__c : Cannot set ControlledByParent on a CustomObject without a
MasterDetail relationship field Form__c.object
Save error:
Form__c.All : In field: columns - no CustomField named
Form__c.Form_Template__c found Form__c.object
Save error:
Form__c.Form_Template__c : referenceTo value of 'Form_Template__c'
does not resolve to a valid sObject type Form__c.object
Save error:
Form_Template__c : formoverride does not exist or is not
a valid override for action Edit. Form_Template__c.object
Save error:
GWAPI_Log__c : log_detail does not exist or is not
a valid override for action View. GWAPI_Log__c.object
Save error:
Idea.Ideas_Last_7_Days : Could not resolve list
view column: IDEA.IDEA_THEME Idea.object
Save error:
Message__c.Form_in_Question__c : referenceTo value of 'Form_Template__c'
does not resolve to a valid sObject type Message__c.object
Save error:
News__c : customarticle does not exist or is not a valid override
for action Edit. News__c.object
Save error:
Question__c : Cannot set ControlledByParent on a CustomObject without
a MasterDetail relationship field Question__c.object
Save error:
Question__c.All : In field: columns - no CustomField named
Question__c.Form_Template__c found Question__c.object
Save error:
Question__c.Form_Template__c : referenceTo value of 'Form_Template__c'
does not resolve to a valid sObject type Question__c.object
Save error:
Section__c : Cannot set ControlledByParent on a CustomObject without
a MasterDetail relationship field Section__c.object
Save error:
Section__c.Form_Template__c : referenceTo value of 'Form_Template__c'
does not resolve to a valid sObject type Section__c.object
Save error:
Security_Question_Answer__c.Question_Text__c : Field Is_Patient__c
does not exist. Check spelling. Security_Question_Answer__c.object
Save error:
sObject type 'Portal_Session__c' is not supported. If you are
attempting to use a custom object, be sure to append the '__c'
after the entity name. Please reference your WSDL or the describe call for the appropriate names.
And so I have to have any luck with the new deployment in either the IDE or via the Migration Tool (MT).
I'm looking for advice on how to approach these issues when deploying to a brand new org using either IDE or MT. The errors imply, I think, something about the ordering of the deployment but as I understand from the Migration Tool Guide, Development Lifecycle Guide, etc the dependencies and ordering can be determined by the platform when deploying.
Have others run into similar issues and found that the solution was strictly in the package.xml? I'm curious because in one instance the package.xml works fine (when deploying to the original org) but in the other case (a new org) it doesn't seem sufficient.
The troubles with a virgin sandboxes is that usually you can't deploy it without a few iterations.
I used the following workflow:
deploy the custom objects which are on relationships with standard objects
deploy standard sObjects
deploy the rest of sObjects
deploy triggers and apex code
deploy VF pages/VF email templates
deploy the rest of metadata
after that I used only migration tool for deployment.
I'd like to suggest you perform deployment of sObjects by one at a time for most significant objects. Also before the deployment please check that all settings of standard objects conform to DevOrg's settings
Also you can try to change API version of metadata.